diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-26 10:18:14 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-26 10:38:38 +0200 |
commit | 68f5ff0ec4ba02712e806df963ba65838522e2bb (patch) | |
tree | 665623ccd549e3b1a62d6b95ee19695d4edc20cd | |
parent | workflows/ci: refactoring (diff) | |
download | cimple-68f5ff0ec4ba02712e806df963ba65838522e2bb.tar.gz cimple-68f5ff0ec4ba02712e806df963ba65838522e2bb.zip |
process: portable exit code processing
-rw-r--r-- | src/process.c | 18 | ||||
-rw-r--r-- | test/py/lib/test_repo.py | 4 |
2 files changed, 14 insertions, 8 deletions
diff --git a/src/process.c b/src/process.c index 3fc866f..1e2583b 100644 --- a/src/process.c +++ b/src/process.c @@ -40,12 +40,20 @@ static int wait_for_child(pid_t pid, int *ec) return ret; } - if (WIFEXITED(status)) + /* The child process reports the lowest 8 bits of its exit code, which + * are treated as an unsigned integer on Linux. + * + * If it was killed by a signal, indicate that by negating the signal + * number. */ + + if (WIFEXITED(status)) { *ec = WEXITSTATUS(status); - else if (WIFSIGNALED(status)) - *ec = status; /* Same as $?. */ - else - *ec = -1; + } else if (WIFSIGNALED(status)) { + *ec = -WTERMSIG(status); + } else { + log_err("This shouldn't happen: %d\n", status); + *ec = 1; + } return 0; } diff --git a/test/py/lib/test_repo.py b/test/py/lib/test_repo.py index eb2786d..af0da68 100644 --- a/test/py/lib/test_repo.py +++ b/test/py/lib/test_repo.py @@ -217,9 +217,7 @@ class TestRepoSegfault(TestRepo): shutil.copy(self.prog_path, self.ci_script_path) def run_exit_code_matches(self, ec): - # If WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV, then the $? - # would be 139. - return ec == 139 + return ec == -11 def run_output_matches(self, output): return "Started the test program.\n" == output.decode() |