harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 0c30b24dd73c1dd5371549eaa3f977b2e3320e96
parent ad7125594c29eb679448a537f7f1c359e18c36db
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Sat, 13 Mar 2021 21:29:18 -0500

Fix rt::wexitstatus

Also check for exiting from a signal in rt::compile

Diffstat:
Mrt/+linux/syscalls.ha | 6+++++-
Mrt/compile.ha | 4+++-
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -33,7 +33,11 @@ export fn wait4(pid: int, status: *int, options: int, rusage: nullable *void) vo syscall4(SYS_wait4, pid: u64, status: uintptr: u64, options: u64, rusage: uintptr: u64); -export fn wexitstatus(status: int) int = status & 0xff00 >> 8; +export fn wifexited(status: int) bool = wtermsig(status) == 0; +export fn wexitstatus(status: int) int = (status & 0xff00) >> 8; + +export fn wtermsig(status: int) int = status & 0x7f; +export fn wifsignaled(status: int) bool = (status & 0xffff) - 1 < 0xff; export fn kill(pid: int, signal: int) int = syscall2(SYS_kill, pid: u64, signal: u64): int; diff --git a/rt/compile.ha b/rt/compile.ha @@ -30,5 +30,7 @@ export fn compile(src: const str) int = { wait4(child, &status, 0, null); }; - return wexitstatus(status); + return if (wifexited(status)) wexitstatus(status) + else if (wifsignaled(status)) wtermsig(status) + else abort(); };