aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-03-08 22:39:57 +0200
committerArnold D. Robbins <arnold@skeeve.com>2016-03-08 22:39:57 +0200
commit3952172ea5f501a92c4ccf8595ebaee34d29377d (patch)
treef176a91b613e63896f51ea62c87d00a8c0961a64 /builtin.c
parent0d76c6de321ecbf2cfda7d681cfce1ca80420be2 (diff)
downloadegawk-3952172ea5f501a92c4ccf8595ebaee34d29377d.tar.gz
egawk-3952172ea5f501a92c4ccf8595ebaee34d29377d.tar.bz2
egawk-3952172ea5f501a92c4ccf8595ebaee34d29377d.zip
Improve algorithm for system() return value.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/builtin.c b/builtin.c
index 375497fa..da664e3a 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2061,7 +2061,7 @@ NODE *
do_system(int nargs)
{
NODE *tmp;
- int ret = 0;
+ AWKNUM ret = 0; /* floating point on purpose, compat Unix awk */
char *cmd;
char save;
@@ -2084,17 +2084,17 @@ do_system(int nargs)
/*
* 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.
+ * divides the result by 256. That normally gives the
+ * exit status but gives a weird result for death-by-signal.
* So we compromise as follows:
*/
if (ret != -1) {
if (do_posix)
; /* leave it alone, full 16 bits */
+ else if (do_traditional)
+ ret /= 256.0;
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;