Blame SOURCES/oprofile-env.patch

e284e3
From b869a61861e161c855379c4b5700fd352da01154 Mon Sep 17 00:00:00 2001
e284e3
From: William Cohen <wcohen@redhat.com>
e284e3
Date: Thu, 8 Jan 2015 16:37:57 -0500
e284e3
Subject: [PATCH] Avoid permanently setting POSIXLY_CORRECT environment
e284e3
 variable
e284e3
e284e3
During testing on Fedora it was discovered that operf was setting the
e284e3
enviroment variable POSIXLY_CORRECT and this could potentially be
e284e3
observed in the children tasks that operf starts (Red Hat Bugzilla
e284e3
1178577). The operf, ocount, and opjitconv commands all ensure that
e284e3
POSIXLY_CORRECT environment variable is set when the options are
e284e3
processed with getopt_long, but they never unset the variable
e284e3
afterwards.  This patch ensures that POSIXLY_CORRECT is as it was
e284e3
before it was set.
e284e3
e284e3
Signed-off-by: William Cohen <wcohen@redhat.com>
e284e3
---
e284e3
 opjitconv/opjitconv.c  | 5 +++++
e284e3
 pe_counting/ocount.cpp | 5 +++++
e284e3
 pe_profiling/operf.cpp | 5 +++++
e284e3
 3 files changed, 15 insertions(+)
e284e3
e284e3
diff --git a/pe_counting/ocount.cpp b/pe_counting/ocount.cpp
e284e3
index 07dfd0c..f7caede 100644
e284e3
--- a/pe_counting/ocount.cpp
e284e3
+++ b/pe_counting/ocount.cpp
e284e3
@@ -579,6 +579,7 @@ static int _process_ocount_and_app_args(int argc, char * const argv[])
e284e3
 {
e284e3
 	bool keep_trying = true;
e284e3
 	int idx_of_non_options = 0;
e284e3
+	char * prev_env = getenv("POSIXLY_CORRECT");
e284e3
 	setenv("POSIXLY_CORRECT", "1", 0);
e284e3
 	while (keep_trying) {
e284e3
 		int option_idx = 0;
e284e3
@@ -663,6 +664,10 @@ static int _process_ocount_and_app_args(int argc, char * const argv[])
e284e3
 			__print_usage_and_exit("ocount: unexpected end of arg parsing");
e284e3
 		}
e284e3
 	}
e284e3
+
e284e3
+	if (prev_env == NULL)
e284e3
+		unsetenv("POSIXLY_CORRECT");
e284e3
+
e284e3
 	return idx_of_non_options;
e284e3
 }
e284e3
 
e284e3
diff --git a/pe_profiling/operf.cpp b/pe_profiling/operf.cpp
e284e3
index 04a25d9..a186278 100644
e284e3
--- a/pe_profiling/operf.cpp
e284e3
+++ b/pe_profiling/operf.cpp
e284e3
@@ -1258,6 +1258,7 @@ static int _process_operf_and_app_args(int argc, char * const argv[])
e284e3
 {
e284e3
 	bool keep_trying = true;
e284e3
 	int idx_of_non_options = 0;
e284e3
+	char * prev_env = getenv("POSIXLY_CORRECT");
e284e3
 	setenv("POSIXLY_CORRECT", "1", 0);
e284e3
 	while (keep_trying) {
e284e3
 		int option_idx = 0;
e284e3
@@ -1331,6 +1332,10 @@ static int _process_operf_and_app_args(int argc, char * const argv[])
e284e3
 			__print_usage_and_exit("unexpected end of arg parsing");
e284e3
 		}
e284e3
 	}
e284e3
+
e284e3
+	if (prev_env == NULL)
e284e3
+		unsetenv("POSIXLY_CORRECT");
e284e3
+
e284e3
 	return idx_of_non_options;
e284e3
 }
e284e3
 
e284e3
-- 
e284e3
2.1.0
e284e3