1 /******************************************************************************
2 * posix_signal.cc - A signal handleing class for linux + solaris *
3 * to convert posix into somthing easier to use *
4 * Tim Hurman - t.hurman@virgin.net *
5 * Last edited on 01th Oct 19999 *
6 ******************************************************************************/
8 * A quick note, fscking linux, none of this would be neccessary if
9 * linux contained support for sighold, sigrelse, sigignore and sigpause.
13 #include <sys/types.h>
15 #include <sys/wait.h> /* header for waitpid() and various macros */
16 #include <signal.h> /* header for signal functions */
23 #include "posix_signal.hh"
26 SigHandler::SigHandler()
31 SigHandler::~SigHandler()
36 int SigHandler::SetSignal(int SIGNAL, SIG_PF ACTION)
40 /* declare what is going to be called when */
41 act.sa_handler = ACTION;
43 /* clear the structure's mask */
44 sigemptyset(&act.sa_mask);
46 /* set up some flags */
47 if(SIGNAL == SIGCHLD) {
48 act.sa_flags = SA_NOCLDSTOP;
51 /* set the signal handler */
52 if(sigaction(SIGNAL, &act, NULL) < 0)
54 std::cerr << "sigaction(): " << strerror(errno) << "\n";
64 int SigHandler::BlockSignal(int SIGNAL)
71 /* add the SIGNAL to the set */
72 sigaddset(&set, SIGNAL);
75 if(sigprocmask(SIG_BLOCK, &set, NULL) < 0)
77 std::cerr << "sigprocmask(): " << strerror(errno) << "\n";
86 /* unblock a signal */
87 int SigHandler::UnBlockSignal(int SIGNAL)
94 /* add the SIGNAL to the set */
95 sigaddset(&set, SIGNAL);
98 if(sigprocmask(SIG_UNBLOCK, &set, NULL) < 0)
100 std::cerr << "sigprocmask(): " << strerror(errno) << "\n";