From 72a97a2e44a300808b5584bd3d3581162b107b03 Mon Sep 17 00:00:00 2001 From: Alexander Zangerl Date: Sun, 22 Jul 2012 12:01:00 -0500 Subject: [PATCH] whatnow cooks up strings for executing external commands, and then feeds these strings to popen or system. These command strings rely on $SHELL being present - and if that is not the case, then we get weird error messages ("sh: -c not found" or similar). (Because both system() and popen() start up fine with the std shell, but their arg string to parse doesn't include a cmdname/path before the -c.) As far as i understand the POSIX standard, SHELL is recommended but not actually mandatory, so i think it would be good to handle this a bit more robustly: by setting SHELL to /bin/sh if not present. --- uip/whatnowsbr.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 1d21bd3..121a79b 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -605,6 +605,11 @@ system_in_dir(const char *dir, const char *cmd) { char olddir[BUFSIZ]; int r; + + /* ensure that $SHELL exists, as the cmd was written relying on + a non-blank $SHELL... */ + setenv("SHELL","/bin/sh",0); /* don't overwrite */ + if (getcwd(olddir, sizeof(olddir)) == 0) adios("getcwd", "could not get working directory"); if (chdir(dir) != 0) @@ -621,6 +626,11 @@ popen_in_dir(const char *dir, const char *cmd, const char *type) { char olddir[BUFSIZ]; FILE *f; + + /* ensure that $SHELL exists, as the cmd was written relying on + a non-blank $SHELL... */ + setenv("SHELL","/bin/sh",0); /* don't overwrite */ + if (getcwd(olddir, sizeof(olddir)) == 0) adios("getcwd", "could not get working directory"); if (chdir(dir) != 0) -- 1.7.10.4