diff options
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -2064,6 +2064,7 @@ do_system(int nargs) AWKNUM ret = 0; /* floating point on purpose, compat Unix awk */ char *cmd; char save; + int status; if (do_sandbox) fatal(_("'system' function not allowed in sandbox mode")); @@ -2080,7 +2081,7 @@ do_system(int nargs) cmd[tmp->stlen] = '\0'; os_restore_mode(fileno(stdin)); - ret = system(cmd); + status = system(cmd); /* * 3/2016. What to do with ret? It's never simple. * POSIX says to use the full return value. BWK awk @@ -2088,17 +2089,23 @@ do_system(int nargs) * exit status but gives a weird result for death-by-signal. * So we compromise as follows: */ - if (ret != -1) { + ret = status; + if (status != -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 (WIFSIGNALED(ret)) + ret = (status / 256.0); + else if (WIFEXITED(status)) + ret = WEXITSTATUS(status); /* normal exit */ + else if (WIFSIGNALED(status)) { + bool coredumped = false; +#ifdef WCOREDUMP + coredumped = WCOREDUMP(status); +#endif /* use 256 since exit values are 8 bits */ - ret = WTERMSIG(ret) + 256; - else + ret = WTERMSIG(status) + + (coredumped ? 512 : 256); + } else ret = 0; /* shouldn't get here */ } if ((BINMODE & BINMODE_INPUT) != 0) |