hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit eded54377ae3132185b51b4dfaf96b5192f4fc77
parent 8b3fae59493b2e2c83ba4a71c6d110861a1f1632
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 11 Apr 2022 17:26:34 +0200

unix::signal: add sigprocmask bits

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mrt/+linux/syscalls.ha | 2+-
Munix/signal/+linux.ha | 28+++++++++++++++++++++++++---
2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -510,7 +510,7 @@ export fn signalfd(fd: int, mask: *const sigset, flags: int) (int | errno) = { export fn sigprocmask( how: int, - set: *const sigset, + set: nullable *const sigset, old: nullable *sigset ) (int | errno) = { return wrap_return(syscall4(SYS_rt_sigprocmask, diff --git a/unix/signal/+linux.ha b/unix/signal/+linux.ha @@ -56,11 +56,33 @@ export fn restore(signum: signal, action: *sigaction) void = { }; }; -// Sets the process's signal mask, returning the previous mask. -export fn procmask(how: how, signals: signal...) sigset = { +// Adds the given list of signals to the process's current signal mask, +// returning the old signal mask. This is a convenience function around +// [[setprocmask]]. +export fn block(signals: signal...) sigset = { + let new = newsigset(signals...); + return setprocmask(how::BLOCK, &new); +}; + +// Removes the given list of signals from the process's current signal mask, +// returning the old signal mask. This is a convenience function around +// [[setprocmask]]. +export fn unblock(signals: signal...) sigset = { let new = newsigset(signals...); + return setprocmask(how::UNBLOCK, &new); +}; + +// Sets the process's signal mask, returning the previous mask. +export fn setprocmask(how: how, mask: *sigset) sigset = { + let old = sigset { ... }; + rt::sigprocmask(how, mask, &old)!; + return old; +}; + +// Gets the current process's signal mask. +export fn getprocmask() sigset = { let old = sigset { ... }; - rt::sigprocmask(how, &new, &old)!; + rt::sigprocmask(how::SETMASK, null, &old)!; return old; };