commit 91ec8e4ab0393484370079b5366645ebadf261f2
parent 01bf6ea04e356fde713f418bd5da31c2ca55a592
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 11 Apr 2022 17:07:55 +0200
unix::signal: improve signalfd interface
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/unix/signal/+linux.ha b/unix/signal/+linux.ha
@@ -140,12 +140,35 @@ export type flag = enum int {
export type signal = int;
-// Creates or updates a signal file. Pass -1 to create a new signalfd, or an
-// existing signalfd to update it.
-export fn signalfd(
+// Creates a signal file.
+export fn signalfd(opt: (flag | sigset)...) (io::file | errors::error) = {
+ let sa_mask = newset();
+
+ let sa_flags = 0, nmask = 0;
+ for (let i = 0z; i < len(opt); i += 1) {
+ match (opt[i]) {
+ case let flag: flag =>
+ sa_flags |= flag;
+ case let mask: sigset =>
+ assert(nmask == 0, "Multiple signal masks provided to signal::signalfd");
+ nmask += 1;
+ sa_mask = mask;
+ };
+ };
+
+ match (rt::signalfd(-1, &sa_mask, sa_flags)) {
+ case let fd: int =>
+ return fd;
+ case let err: rt::errno =>
+ return errors::errno(err);
+ };
+};
+
+// Updates a signalfd with new options.
+export fn update(
fd: io::file,
opt: (flag | sigset)...
-) (io::file | errors::error) = {
+) (void | errors::error) = {
let sa_mask = newset();
let sa_flags = 0, nmask = 0;
@@ -154,15 +177,15 @@ export fn signalfd(
case let flag: flag =>
sa_flags |= flag;
case let mask: sigset =>
- assert(nmask == 0, "Multiple signal masks provided to signal::handle");
+ assert(nmask == 0, "Multiple signal masks provided to signal::update");
nmask += 1;
sa_mask = mask;
};
};
match (rt::signalfd(fd, &sa_mask, sa_flags)) {
- case let fd: int =>
- return fd;
+ case int =>
+ return;
case let err: rt::errno =>
return errors::errno(err);
};