Blame SOURCES/oprofile-env.patch

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