Blame SOURCES/oprofile-env.patch

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