1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/******************************************************************************
* posix_signal.cc - A signal handleing class for linux + solaris *
* to convert posix into somthing easier to use *
* Tim Hurman - t.hurman@virgin.net *
* Last edited on 01th Oct 19999 *
******************************************************************************/
/*
* A quick note, fscking linux, none of this would be neccessary if
* linux contained support for sighold, sigrelse, sigignore and sigpause.
*
*/
#include <sys/types.h>
#include <iostream>
#include <sys/wait.h> /* header for waitpid() and various macros */
#include <signal.h> /* header for signal functions */
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include "posix_signal.hh"
// constructor
SigHandler::SigHandler()
{
}
// destructor
SigHandler::~SigHandler()
{
}
/* set a signal */
int SigHandler::SetSignal(int SIGNAL, SIG_PF ACTION)
{
struct sigaction act;
/* declare what is going to be called when */
act.sa_handler = ACTION;
/* clear the structure's mask */
sigemptyset(&act.sa_mask);
/* set up some flags */
if(SIGNAL == SIGCHLD) {
act.sa_flags = SA_NOCLDSTOP;
}
/* set the signal handler */
if(sigaction(SIGNAL, &act, NULL) < 0)
{
std::cerr << "sigaction(): " << strerror(errno) << "\n";
exit(-1);
}
/* all ok */
return(0);
}
/* block a signal */
int SigHandler::BlockSignal(int SIGNAL)
{
sigset_t set;
/* initalise */
sigemptyset(&set);
/* add the SIGNAL to the set */
sigaddset(&set, SIGNAL);
/* block it */
if(sigprocmask(SIG_BLOCK, &set, NULL) < 0)
{
std::cerr << "sigprocmask(): " << strerror(errno) << "\n";
exit(-1);
}
/* done */
return(0);
}
/* unblock a signal */
int SigHandler::UnBlockSignal(int SIGNAL)
{
sigset_t set;
/* initalise */
sigemptyset(&set);
/* add the SIGNAL to the set */
sigaddset(&set, SIGNAL);
/* block it */
if(sigprocmask(SIG_UNBLOCK, &set, NULL) < 0)
{
std::cerr << "sigprocmask(): " << strerror(errno) << "\n";
exit(-1);
}
/* done */
return(0);
}
|