commit da96d4948ba6261ffbdd7d923ceb53b2b08f7eac
parent 3d269ac418c31cc959fcb025265f0995400919ae
Author: Sebastian <sebastian@sebsite.pw>
Date: Wed, 31 May 2023 01:06:03 -0400
os::exec: split kill into kill and sig
This removes the variadism from kill, giving it only one purpose, that
being to kill a process (by raising SIGTERM). A new function called sig
is added to send an arbitrary signal to a process. This also creates a
clear distinction between what's portable and what depends on a
Unix-like system. Also, now that unix::signal is ported to FreeBSD, the
signal enum was removed, instead using the signal type within
unix::signal.
References: https://todo.sr.ht/~sircmpwn/hare/841
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
2 files changed, 14 insertions(+), 98 deletions(-)
diff --git a/os/exec/process+freebsd.ha b/os/exec/process+freebsd.ha
@@ -198,57 +198,15 @@ export fn check(stat: *status) (void | !exit_status) = {
return exit(stat);
};
-// An enumeration of all known signals. Only a subset of these are defined by
-// POSIX, consult the specification for details:
-//
-// https://pubs.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html
-export type signal = enum int {
- SIGHUP = rt::SIGHUP,
- SIGINT = rt::SIGINT,
- SIGQUIT = rt::SIGQUIT,
- SIGILL = rt::SIGILL,
- SIGTRAP = rt::SIGTRAP,
- SIGABRT = rt::SIGABRT,
- SIGFPE = rt::SIGFPE,
- SIGKILL = rt::SIGKILL,
- SIGBUS = rt::SIGBUS,
- SIGSEGV = rt::SIGSEGV,
- SIGSYS = rt::SIGSYS,
- SIGPIPE = rt::SIGPIPE,
- SIGALRM = rt::SIGALRM,
- SIGTERM = rt::SIGTERM,
- SIGSTOP = rt::SIGSTOP,
- SIGTSTP = rt::SIGTSTP,
- SIGCONT = rt::SIGCONT,
- SIGCHLD = rt::SIGCHLD,
- SIGTTIN = rt::SIGTTIN,
- SIGTTOU = rt::SIGTTOU,
- SIGIO = rt::SIGIO,
- SIGXCPU = rt::SIGXCPU,
- SIGXFSZ = rt::SIGXFSZ,
- SIGVTALRM = rt::SIGVTALRM,
- SIGPROF = rt::SIGPROF,
- SIGWINCH = rt::SIGWINCH,
- SIGINFO = rt::SIGINFO,
- SIGUSR1 = rt::SIGUSR1,
- SIGUSR2 = rt::SIGUSR2,
- SIGTHR = rt::SIGTHR,
- SIGLWP = rt::SIGLWP,
- SIGLIBRT = rt::SIGLIBRT,
+// Terminates a process. On FreeBSD, this sends [[unix::signal::SIGTERM]] to the
+// process.
+export fn kill(proc: process) (void | errors::error) = {
+ return sig(proc, signal::SIGTERM);
};
-// Sends a signal to a child process. If no variadic arguments are provided, the
-// program is terminated in a platform-specific manner. You may provide exactly
-// one variadic argument, the [[signal]] you wish to send, but this is only
-// supported on Unix-like systems.
-export fn kill(proc: process, sig: signal...) (void | errors::error) = {
- const sig = if (len(sig) == 0) {
- yield signal::SIGTERM;
- } else if (len(sig) == 1) {
- yield sig[0];
- } else {
- abort("os::exec::signal illegally called with more than one signal");
- };
+// Sends a signal to a child process. This function is only supported on
+// Unix-like systems.
+export fn sig(proc: process, sig: signal::signal) (void | errors::error) = {
match (rt::kill(proc, sig)) {
case let errno: rt::errno =>
return errors::errno(errno);
diff --git a/os/exec/process+linux.ha b/os/exec/process+linux.ha
@@ -184,57 +184,15 @@ export fn check(stat: *status) (void | !exit_status) = {
return exit(stat);
};
-// An enumeration of all known signals. Only a subset of these are defined by
-// POSIX, consult the specification for details:
-//
-// https://pubs.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html
-export type signal = enum int {
- SIGHUP = rt::SIGHUP,
- SIGINT = rt::SIGINT,
- SIGQUIT = rt::SIGQUIT,
- SIGILL = rt::SIGILL,
- SIGTRAP = rt::SIGTRAP,
- SIGABRT = rt::SIGABRT,
- SIGBUS = rt::SIGBUS,
- SIGFPE = rt::SIGFPE,
- SIGKILL = rt::SIGKILL,
- SIGUSR1 = rt::SIGUSR1,
- SIGSEGV = rt::SIGSEGV,
- SIGUSR2 = rt::SIGUSR2,
- SIGPIPE = rt::SIGPIPE,
- SIGALRM = rt::SIGALRM,
- SIGTERM = rt::SIGTERM,
- SIGSTKFLT = rt::SIGSTKFLT,
- SIGCHLD = rt::SIGCHLD,
- SIGCONT = rt::SIGCONT,
- SIGSTOP = rt::SIGSTOP,
- SIGTSTP = rt::SIGTSTP,
- SIGTTIN = rt::SIGTTIN,
- SIGTTOU = rt::SIGTTOU,
- SIGURG = rt::SIGURG,
- SIGXCPU = rt::SIGXCPU,
- SIGXFSZ = rt::SIGXFSZ,
- SIGVTALRM = rt::SIGVTALRM,
- SIGPROF = rt::SIGPROF,
- SIGWINCH = rt::SIGWINCH,
- SIGIO = rt::SIGIO,
- SIGPOLL = rt::SIGPOLL,
- SIGPWR = rt::SIGPWR,
- SIGSYS = rt::SIGSYS,
+// Terminates a process. On Linux, this sends [[unix::signal::SIGTERM]] to the
+// process.
+export fn kill(proc: process) (void | errors::error) = {
+ return sig(proc, signal::SIGTERM);
};
-// Sends a signal to a child process. If no variadic arguments are provided, the
-// program is terminated in a platform-specific manner. You may provide exactly
-// one variadic argument, the [[signal]] you wish to send, but this is only
-// supported on Unix-like systems.
-export fn kill(proc: process, sig: signal...) (void | errors::error) = {
- const sig = if (len(sig) == 0) {
- yield signal::SIGTERM;
- } else if (len(sig) == 1) {
- yield sig[0];
- } else {
- abort("os::exec::signal illegally called with more than one signal");
- };
+// Sends a signal to a child process. This function is only supported on
+// Unix-like systems.
+export fn sig(proc: process, sig: signal::signal) (void | errors::error) = {
match (rt::kill(proc, sig)) {
case let errno: rt::errno =>
return errors::errno(errno);