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.
{
char olddir[BUFSIZ];
int r;
{
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)
if (getcwd(olddir, sizeof(olddir)) == 0)
adios("getcwd", "could not get working directory");
if (chdir(dir) != 0)
{
char olddir[BUFSIZ];
FILE *f;
{
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)
if (getcwd(olddir, sizeof(olddir)) == 0)
adios("getcwd", "could not get working directory");
if (chdir(dir) != 0)