From: Alexander Zangerl Date: Sun, 22 Jul 2012 17:01:00 +0000 (-0500) Subject: whatnow cooks up strings for executing external commands, and then X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=72a97a2e44a300808b5584bd3d3581162b107b03;p=mmh 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. --- 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)