1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-18 03:09:56 +00:00

Fixes #316: os/execute should return non-zero on signals

Behave more like shells, and catch segfaults.
This commit is contained in:
Calvin Rose 2020-03-18 17:46:02 -05:00
parent b0d8369534
commit 3b5183a74e

View File

@ -401,7 +401,16 @@ static Janet os_execute(int32_t argc, Janet *argv) {
}
os_execute_cleanup(envp, child_argv);
return janet_wrap_integer(WEXITSTATUS(status));
/* Use POSIX shell semantics for interpreting signals */
int ret;
if (WIFEXITED(status)) {
ret = WEXITSTATUS(status);
} else if (WIFSTOPPED(status)) {
ret = WSTOPSIG(status) + 128;
} else {
ret = WTERMSIG(status) + 128;
}
return janet_wrap_integer(ret);
#endif
}