nmh-workers
[Top] [All Lists]

[Nmh-workers] whatnow brittle wrt. $SHELL

2012-07-22 00:30:40
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.

the attached trivial patch uses setenv() with overwrite=0 to achieve that.

regards
az

#! /bin/sh /usr/share/dpatch/dpatch-run
## 07-shell.dpatch by  <az(_at_)debian(_dot_)org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: workaround for #682362 (debuild nukes $SHELL)

@DPATCH@
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' 
'--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' 
nmh-1.5-release~/uip/whatnowsbr.c nmh-1.5-release/uip/whatnowsbr.c
--- nmh-1.5-release~/uip/whatnowsbr.c   2012-07-22 12:19:48.742288837 +1000
+++ nmh-1.5-release/uip/whatnowsbr.c    2012-07-22 12:22:00.145064615 +1000
@@ -605,6 +605,11 @@
 {
     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 @@
 {
     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)
-- 
Alexander Zangerl + GnuPG Keys 0x42BD645D or 0x5B586291 + http://snafu.priv.at/
The idea is that RAID stands for Redundant Array of Inexpensive Dreck. 
 -- Anthony de Boer

Attachment: signature.asc
Description: Digital Signature

_______________________________________________
Nmh-workers mailing list
Nmh-workers(_at_)nongnu(_dot_)org
https://lists.nongnu.org/mailman/listinfo/nmh-workers
<Prev in Thread] Current Thread [Next in Thread>