Patch by Vasilis Kaoutsis (modified by myself): Implemented sigset().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22947 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -147,6 +147,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
sighandler_t signal(int sig, sighandler_t signalHandler);
|
||||
sighandler_t sigset(int sig, sighandler_t signalHandler);
|
||||
int raise(int sig);
|
||||
int kill(pid_t pid, int sig);
|
||||
int send_signal(pid_t tid, unsigned int sig);
|
||||
|
||||
@@ -7,6 +7,7 @@ MergeObject posix_signal.o :
|
||||
killpg.cpp
|
||||
raise.c
|
||||
send_signal.c
|
||||
set_signal_disposition.cpp
|
||||
set_signal_stack.c
|
||||
sigaction.c
|
||||
sigaltstack.c
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2007, Vasilis Kaoutsis, [email protected]
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
sighandler_t
|
||||
sigset(int signal, sighandler_t signalHandler)
|
||||
{
|
||||
struct sigaction newAction;
|
||||
struct sigaction oldAction;
|
||||
|
||||
newAction.sa_handler = signalHandler;
|
||||
newAction.sa_flags = 0;
|
||||
if (signal == SIGCHLD && signalHandler == SIG_IGN) {
|
||||
// In case of SIGCHLD the specification requires SA_NOCLDWAIT behavior.
|
||||
newAction.sa_flags |= SA_NOCLDWAIT;
|
||||
}
|
||||
|
||||
sigemptyset(&newAction.sa_mask);
|
||||
if (sigaction(signal, signalHandler == SIG_HOLD ? NULL : &newAction,
|
||||
&oldAction) == -1) {
|
||||
return SIG_ERR;
|
||||
}
|
||||
|
||||
sigset_t newSet;
|
||||
sigset_t oldSet;
|
||||
|
||||
sigemptyset(&newSet);
|
||||
sigaddset(&newSet, signal);
|
||||
|
||||
if (signalHandler == SIG_HOLD) {
|
||||
if (sigprocmask(SIG_BLOCK, &newSet, &oldSet) == -1)
|
||||
return SIG_ERR;
|
||||
} else {
|
||||
// Disposition is not equal to SIG_HOLD, so sig will be
|
||||
// removed from the calling process' signal mask.
|
||||
if (sigprocmask(SIG_UNBLOCK, &newSet, &oldSet) == -1)
|
||||
return SIG_ERR;
|
||||
}
|
||||
|
||||
if (sigismember(&oldSet, signal))
|
||||
return SIG_HOLD;
|
||||
else
|
||||
return oldAction.sa_handler;
|
||||
}
|
||||
Reference in New Issue
Block a user