Implement signals, finally! #30
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user