[PATCH] Avoid permanently setting POSIXLY_CORRECT environment variable
William Cohen <[email protected]>
| Newsgroups | gmane.linux.oprofile |
|---|---|
| Message-ID | <[email protected]> |
During testing on Fedora it was discovered that operf was setting the enviroment variable POSIXLY_CORRECT and this could potentially be observed in the children tasks that operf starts (Red Hat Bugzilla 1178577). The operf, ocount, and opjitconv commands all ensure that POSIXLY_CORRECT environment variable is set when the options are processed with getopt_long, but they never unset the variable afterwards. This patch ensures that POSIXLY_CORRECT is as it was before it was set. Signed-off-by: William Cohen <[email protected]> --- opjitconv/opjitconv.c | 5 +++++ pe_counting/ocount.cpp | 5 +++++ pe_profiling/operf.cpp | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/opjitconv/opjitconv.c b/opjitconv/opjitconv.c index 0a6e738..e28bd29 100644 --- a/opjitconv/opjitconv.c +++ b/opjitconv/opjitconv.c @@ -819,6 +819,7 @@ static int _process_args(int argc, char * const argv[]) { int keep_trying = 1; int idx_of_non_options = 0; + char * prev_env = getenv("POSIXLY_CORRECT"); setenv("POSIXLY_CORRECT", "1", 0); while (keep_trying) { int option_idx = 0; @@ -853,6 +854,10 @@ static int _process_args(int argc, char * const argv[]) break; } } + + if (prev_env == NULL) + unsetenv("POSIXLY_CORRECT"); + return idx_of_non_options; } diff --git a/pe_counting/ocount.cpp b/pe_counting/ocount.cpp index 07dfd0c..f7caede 100644 --- a/pe_counting/ocount.cpp +++ b/pe_counting/ocount.cpp @@ -579,6 +579,7 @@ static int _process_ocount_and_app_args(int argc, char * const argv[]) { bool keep_trying = true; int idx_of_non_options = 0; + char * prev_env = getenv("POSIXLY_CORRECT"); setenv("POSIXLY_CORRECT", "1", 0); while (keep_trying) { int option_idx = 0; @@ -663,6 +664,10 @@ static int _process_ocount_and_app_args(int argc, char * const argv[]) __print_usage_and_exit("ocount: unexpected end of arg parsing"); } } + + if (prev_env == NULL) + unsetenv("POSIXLY_CORRECT"); + return idx_of_non_options; } diff --git a/pe_profiling/operf.cpp b/pe_profiling/operf.cpp index 04a25d9..a186278 100644 --- a/pe_profiling/operf.cpp +++ b/pe_profiling/operf.cpp @@ -1258,6 +1258,7 @@ static int _process_operf_and_app_args(int argc, char * const argv[]) { bool keep_trying = true; int idx_of_non_options = 0; + char * prev_env = getenv("POSIXLY_CORRECT"); setenv("POSIXLY_CORRECT", "1", 0); while (keep_trying) { int option_idx = 0; @@ -1331,6 +1332,10 @@ static int _process_operf_and_app_args(int argc, char * const argv[]) __print_usage_and_exit("unexpected end of arg parsing"); } } + + if (prev_env == NULL) + unsetenv("POSIXLY_CORRECT"); + return idx_of_non_options; } -- 2.1.0 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net