aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-03-08 06:36:34 +0200
committerArnold D. Robbins <arnold@skeeve.com>2016-03-08 07:14:40 +0200
commit0d76c6de321ecbf2cfda7d681cfce1ca80420be2 (patch)
treec68abb9c3e3f13b728feca952cdc6f69200fdbf3 /builtin.c
parentd12f05fc27089821c78a53858f8ca60ef039d8a1 (diff)
downloadegawk-0d76c6de321ecbf2cfda7d681cfce1ca80420be2.tar.gz
egawk-0d76c6de321ecbf2cfda7d681cfce1ca80420be2.tar.bz2
egawk-0d76c6de321ecbf2cfda7d681cfce1ca80420be2.zip
Improve return value of system.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/builtin.c b/builtin.c
index a62437a2..375497fa 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2081,8 +2081,26 @@ do_system(int nargs)
os_restore_mode(fileno(stdin));
ret = system(cmd);
- if (ret != -1)
- ret = WEXITSTATUS(ret);
+ /*
+ * 3/2016. What to do with ret? It's never simple.
+ * POSIX says to use the full return value. BWK awk
+ * uses just the exit status. That seems more useful to
+ * me, but then death by signal info gets lost.
+ * So we compromise as follows:
+ */
+ if (ret != -1) {
+ if (do_posix)
+ ; /* leave it alone, full 16 bits */
+ else if (WIFEXITED(ret))
+ ret = WEXITSTATUS(ret); /* normal exit */
+ else if (do_traditional)
+ ret = 0; /* ignore signal death */
+ else if (WIFSIGNALED(ret))
+ /* use 256 since exit values are 8 bits */
+ ret = WTERMSIG(ret) + 256;
+ else
+ ret = 0; /* shouldn't get here */
+ }
if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(fileno(stdin), O_BINARY);