Implement signals, finally! #30

Merged
apio merged 14 commits from finally-signals into main 2023-07-10 20:16:00 +00:00
2 changed files with 17 additions and 0 deletions
Showing only changes of commit 4a5947e10e - Show all commits

View File

@ -8,6 +8,8 @@
typedef int sig_atomic_t;
#define SIG_ERR (__simple_sighandler_t)(-3)
#ifdef __cplusplus
extern "C"
{
@ -19,6 +21,9 @@ extern "C"
int sigaction(int signo, const struct sigaction* act, struct sigaction* oldact);
#pragma GCC pop_options
/* Change the current thread's signal disposition for a specific signal. */
__simple_sighandler_t signal(int signo, __simple_sighandler_t handler);
/* Send a signal to a specific process. */
int kill(pid_t pid, int signo);

View File

@ -13,6 +13,18 @@ extern "C"
__errno_return(rc, int);
}
__simple_sighandler_t signal(int signo, __simple_sighandler_t handler)
{
struct sigaction act, oldact;
act.sa_handler = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sigaction(signo, &act, &oldact) < 0) return SIG_ERR;
return oldact.sa_handler;
}
int kill(pid_t pid, int signo)
{
long rc = syscall(SYS_kill, pid, signo);