Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion kklib/src/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,15 @@ kk_decl_export int kk_os_run_system(kk_string_t cmd, kk_context_t* ctx) {
}
#else
kk_with_string_as_qutf8_borrow(cmd, ccmd, ctx) {
exitcode = system(ccmd);
int status = system(ccmd);
if (WIFEXITED(status)) {
exitcode = WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
exitcode = -WTERMSIG(status); // Like Haskell, return negative code for signal termination
} else {
// Technically WIFSTOPPED(status) can happen, but only if the process is being traced, or the call was done with WUNTRACED.
kk_fatal_error(EINVAL, "kk_os_run_system: unexpected termination");
}
}
#endif
kk_string_drop(cmd, ctx);
Expand Down