diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-07-02 12:55:19 -0400 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-07-02 12:55:19 -0400 |
commit | cf2bcf6c7afa8eb7a54e01f98a9998a7e1ac0852 (patch) | |
tree | 3739ed79238c65567ad1001a4f80856af652f660 /lib | |
parent | 6b6051606175d870bb45bbe67866c1643d4d964a (diff) | |
download | monitoring-plugins-cf2bcf6c7afa8eb7a54e01f98a9998a7e1ac0852.tar.gz |
Fix cmd_run overwriting the environment
Some commands need the environment to function properly. One such
example is check_ssh and check_by_ssh when a SOCKS proxy is required.
This patch use setenv and extern char **environ to alter and pass the
new environment to the child process Those modules have been added to
Gnulib for portability.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils_cmd.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index e10ab918..0c853dcc 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c @@ -48,6 +48,9 @@ # include <sys/wait.h> #endif +/* used in _cmd_open to pass the environment to commands */ +extern char **environ; + /** macros **/ #ifndef WEXITSTATUS # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) @@ -122,7 +125,6 @@ cmd_init (void) static int _cmd_open (char *const *argv, int *pfd, int *pfderr) { - char *env[2]; pid_t pid; #ifdef RLIMIT_CORE struct rlimit limit; @@ -137,8 +139,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) if (!_cmd_pids) CMD_INIT; - env[0] = strdup ("LC_ALL=C"); - env[1] = '\0'; + setenv("LC_ALL", "C", 1); if (pipe (pfd) < 0 || pipe (pfderr) < 0 || (pid = fork ()) < 0) return -1; /* errno set by the failing function */ @@ -169,7 +170,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) if (_cmd_pids[i] > 0) close (i); - execve (argv[0], argv, env); + execve (argv[0], argv, environ); _exit (STATE_UNKNOWN); } |