diff --git a/headers/posix/signal.h b/headers/posix/signal.h index 8ef1e9a575..70b139d3b5 100644 --- a/headers/posix/signal.h +++ b/headers/posix/signal.h @@ -163,6 +163,7 @@ int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signo); int sigdelset(sigset_t *set, int signo); int sigismember(const sigset_t *set, int signo); +int sigignore(int signo); const char *strsignal(int sig); diff --git a/src/system/libroot/posix/signal/Jamfile b/src/system/libroot/posix/signal/Jamfile index f3fffb2ee3..02d491b617 100644 --- a/src/system/libroot/posix/signal/Jamfile +++ b/src/system/libroot/posix/signal/Jamfile @@ -10,6 +10,7 @@ MergeObject posix_signal.o : set_signal_stack.c sigaction.c sigaltstack.c + sigignore.cpp signal.c sigpending.c sigprocmask.c diff --git a/src/system/libroot/posix/signal/sigignore.cpp b/src/system/libroot/posix/signal/sigignore.cpp new file mode 100644 index 0000000000..40313868fb --- /dev/null +++ b/src/system/libroot/posix/signal/sigignore.cpp @@ -0,0 +1,37 @@ +/* + * Copyright 2007, Vasilis Kaoutsis, kaoutsis@sch.gr + * Distributed under the terms of the MIT License. + */ + + +#include +#include + +#include + + +int +sigignore(int signal) +{ + // check for invalid signals or for signals + // that can not be ignored (SIGKILL, SIGSTOP) + if (signal <= 0 || signal >= NSIG || signal == SIGKILL + || signal == SIGSTOP) { + errno = EINVAL; + return -1; + } + + struct sigaction ignoreSignalAction; + // create an action to ignore the signal + + // request that the signal will be ignored + // by the handler of the action + ignoreSignalAction.sa_handler = SIG_IGN; + ignoreSignalAction.sa_flags = 0; + + // In case of SIGCHLD the specification requires SA_NOCLDWAIT behavior. + if (signal == SIGCHLD) + ignoreSignalAction.sa_flags |= SA_NOCLDWAIT; + + return sigaction(signal, &ignoreSignalAction, NULL); +}