Gary V. Vaughan <gary <at> gnu.org> writes: > > What is sysval after this run? > > > > $ echo 'changequote([,])syscmd([echo "meh" && kill -9 $$ || > > echo "oops: $?"])sysval' | ./src/m4 > > Oh yeah. D'uh, should've thought of that myself! > > % echo 'changequote([,])syscmd([echo "meh" && kill -9 $$ || > echo "oops: $?"])sysval' | ./src/m4 > meh > 127
What if you replace the || with ; in the syscmd? Or how about: echo 'changequote([,])syscmd([sh -c '\''kill -9 $$'\''; st=$?; echo $st; exit $st])sysval' | ./src/m4 Also, do you have anything like strace or truss, that can see what syscalls were in play during syscmd's use of system()? Maybe this slimmed down program is helpful as a debugging aid: $ cat foo.c #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <sys/wait.h> int main (int argc, char **argv) { int r = system (argc == 1 ? "kill -9 $$" : argv[1]); printf ("%04x %d\n", r, errno); if (fork ()) { wait (&r); printf ("%04x %d\n", r, errno); } else { execlp ("sh", "sh", "-c", argc == 1 ? "kill -9 $$" : argv[1], (char*) 0); } return 0; } $ ./foo false 0100 0 0100 0 $ ./foo 0009 0 0009 0 On my system, the lower 7 bits represent signals, the upper 8 represent normal return (on some platforms, this setup is swapped). The intent of the m4 test is to find some portable way to cause sysval's child process to exit with a signal (since we document that sysval distinguishes signals from normal exit, similar to Solaris m4), hence the attempt to use 'kill -9 $$' since that is unblockable. I'm starting to wonder if AIX system() is massaging the return value from wait(); maybe the gnulib 'execute' module is worthwhile. Similar questions apply to popen() for esyscmd. -- Eric Blake