summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net.c4
-rw-r--r--omusrmsg.c15
-rw-r--r--rfc3195d.c14
-rwxr-xr-xsrUtils.c11
-rw-r--r--syslogd.c85
5 files changed, 100 insertions, 29 deletions
diff --git a/net.c b/net.c
index 3b197cb9..ddc54695 100644
--- a/net.c
+++ b/net.c
@@ -132,7 +132,7 @@ int cvthname(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN)
if (!DisableDNS) {
sigemptyset(&nmask);
sigaddset(&nmask, SIGHUP);
- sigprocmask(SIG_BLOCK, &nmask, &omask);
+ pthread_sigmask(SIG_BLOCK, &nmask, &omask);
error = getnameinfo((struct sockaddr *)f, sizeof(*f),
(char*)pszHostFQDN, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
@@ -182,7 +182,7 @@ int cvthname(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN)
error = 1; /* that will trigger using IP address below. */
}
}
- sigprocmask(SIG_SETMASK, &omask, NULL);
+ pthread_sigmask(SIG_SETMASK, &omask, NULL);
}
if (error || DisableDNS) {
diff --git a/omusrmsg.c b/omusrmsg.c
index 0697b59c..3af0c325 100644
--- a/omusrmsg.c
+++ b/omusrmsg.c
@@ -158,6 +158,7 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData)
static int reenter = 0;
struct utmp ut;
struct utmp *uptr;
+ struct sigaction sigAct;
assert(pMsg != NULL);
@@ -172,12 +173,17 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData)
* and doing notty().
*/
if (fork() == 0) {
- signal(SIGTERM, SIG_DFL);
+ memset(&sigAct, 0, sizeof(sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = SIG_DFL;
+ sigaction(SIGTERM, &sigAct, NULL);
alarm(0);
+
# ifdef SIGTTOU
- signal(SIGTTOU, SIG_IGN);
+ sigAct.sa_handler = SIG_DFL;
+ sigaction(SIGTERM, &sigAct, NULL);
# endif
- sigsetmask(0);
+ sigprocmask(SIG_SETMASK, &sigAct.sa_mask, NULL);
/* TODO: find a way to limit the max size of the message. hint: this
* should go into the template!
*/
@@ -219,7 +225,8 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData)
strncat(p, ut.ut_line, UNAMESZ);
if (setjmp(ttybuf) == 0) {
- (void) signal(SIGALRM, endtty);
+ sigAct.sa_handler = endtty;
+ sigaction(SIGALRM, &sigAct, NULL);
(void) alarm(15);
/* open the terminal */
ttyf = open(p, O_WRONLY|O_NOCTTY);
diff --git a/rfc3195d.c b/rfc3195d.c
index ee7891be..2a06d699 100644
--- a/rfc3195d.c
+++ b/rfc3195d.c
@@ -194,6 +194,7 @@ int main(int argc, char* argv[])
{
srRetVal iRet;
int ch;
+ struct sigaction_t sigAct;
while ((ch = getopt(argc, argv, "di:np:r:v")) != EOF)
switch((char)ch) {
@@ -231,10 +232,17 @@ int main(int argc, char* argv[])
if ((argc -= optind))
usage();
+ memset(&sigAct, 0, sizeof(sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = doShutdown;
+ sigaction(SIGUSR1, &sigAct, NULL);
+ sigaction(SIGTERM, &sigAct, NULL);
+
if(!Debug)
- signal(SIGINT, SIG_IGN);
- signal(SIGUSR1, doShutdown);
- signal(SIGTERM, doShutdown);
+ {
+ sigAct.sa_handler = SIG_IGN;
+ sigaction(SIGINT, &sigAct, NULL);
+ }
if((pAPI = srAPIInitLib()) == NULL)
{
diff --git a/srUtils.c b/srUtils.c
index 0aed9de8..843e6f72 100755
--- a/srUtils.c
+++ b/srUtils.c
@@ -173,6 +173,7 @@ int execProg(uchar *program, int bWait, uchar *arg)
{
int pid;
int sig;
+ struct sigaction sigAct;
dbgprintf("exec program '%s' with param '%s'\n", program, arg);
pid = fork();
@@ -196,8 +197,14 @@ int execProg(uchar *program, int bWait, uchar *arg)
}
/* Child */
alarm(0); /* create a clean environment before we exec the real child */
- for(sig = 0 ; sig < 32 ; ++sig)
- signal(sig, SIG_DFL);
+
+ memset(&sigAct, 0, sizeof(sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = SIG_DFL;
+
+ for(sig = 1 ; sig < NSIG ; ++sig)
+ sigaction(sig, &sigAct, NULL);
+
execlp((char*)program, (char*) program, (char*)arg, NULL);
/* In the long term, it's a good idea to implement some enhanced error
* checking here. However, it can not easily be done. For starters, we
diff --git a/syslogd.c b/syslogd.c
index 9561cf75..4ad14ecc 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -2710,9 +2710,13 @@ static void *singleWorker()
{
msgQueue *fifo = pMsgQueue;
msg_t *pMsg;
+ sigset_t sigSet;
assert(fifo != NULL);
+ sigfillset(&sigSet);
+ pthread_sigmask(SIG_BLOCK, &sigSet, NULL);
+
while(!bGlblDone || !fifo->empty) {
pthread_mutex_lock(fifo->mut);
while (fifo->empty && !bGlblDone) {
@@ -3369,7 +3373,13 @@ finalize_it:
static void reapchild()
{
int saved_errno = errno;
- signal(SIGCHLD, reapchild); /* reset signal handler -ASP */
+ struct sigaction sigAct;
+
+ memset(&sigAct, 0, sizeof (sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = reapchild;
+ sigaction(SIGCHLD, &sigAct, NULL); /* reset signal handler -ASP */
+
while(waitpid(-1, NULL, WNOHANG) > 0);
errno = saved_errno;
}
@@ -3436,17 +3446,30 @@ static void domark(void)
*/
static void domarkAlarmHdlr()
{
- bRequestDoMark = 1; /* request alarm */
- (void) signal(SIGALRM, domarkAlarmHdlr);
- (void) alarm(TIMERINTVL);
+ struct sigaction sigAct;
+
+ bRequestDoMark = 1; /* request alarm */
+
+ memset(&sigAct, 0, sizeof (sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = domarkAlarmHdlr;
+ sigaction(SIGALRM, &sigAct, NULL);
+
+ (void) alarm(TIMERINTVL);
}
static void debug_switch()
{
- dbgprintf("Switching debugging_on to %s\n", (debugging_on == 0) ? "true" : "false");
- debugging_on = (debugging_on == 0) ? 1 : 0;
- signal(SIGUSR1, debug_switch);
+ struct sigaction sigAct;
+
+ dprintf("Switching debugging_on to %s\n", (debugging_on == 0) ? "true" : "false");
+ debugging_on = (debugging_on == 0) ? 1 : 0;
+
+ memset(&sigAct, 0, sizeof (sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = debug_switch;
+ sigaction(SIGUSR1, &sigAct, NULL);
}
@@ -4240,6 +4263,7 @@ static void init(void)
#endif
char bufStartUpMsg[512];
struct servent *sp;
+ struct sigaction sigAct;
/* initialize some static variables */
pDfltHostnameCmp = NULL;
@@ -4435,7 +4459,11 @@ static void init(void)
);
logmsgInternal(LOG_SYSLOG|LOG_INFO, bufStartUpMsg, ADDDATE);
- (void) signal(SIGHUP, sighup_handler);
+ memset(&sigAct, 0, sizeof (sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = sighup_handler;
+ sigaction(SIGHUP, &sigAct, NULL);
+
dbgprintf(" restarted.\n");
}
@@ -5316,8 +5344,15 @@ void dbgprintf(char *fmt, ...)
*/
void sighup_handler()
{
+ struct sigaction sigAct;
+
restart = 1;
- signal(SIGHUP, sighup_handler);
+
+ memset(&sigAct, 0, sizeof (sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = sighup_handler;
+ sigaction(SIGHUP, &sigAct, NULL);
+
return;
}
@@ -5998,6 +6033,7 @@ int main(int argc, char **argv)
extern int optind;
extern char *optarg;
uchar *pTmp;
+ struct sigaction sigAct;
if(chdir ("/") != 0)
fprintf(stderr, "Can not do 'cd /' - still trying to run\n");
@@ -6131,7 +6167,11 @@ int main(int argc, char **argv)
dbgprintf("Checking pidfile.\n");
if (!check_pid(PidFile))
{
- signal (SIGTERM, doexit);
+ memset(&sigAct, 0, sizeof (sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = doexit;
+ sigaction(SIGTERM, &sigAct, NULL);
+
if (fork()) {
/*
* Parent process
@@ -6233,14 +6273,23 @@ int main(int argc, char **argv)
if (isupper((int) *p))
*p = tolower(*p);
- (void) signal(SIGTERM, doDie);
- (void) signal(SIGINT, Debug ? doDie : SIG_IGN);
- (void) signal(SIGQUIT, Debug ? doDie : SIG_IGN);
- (void) signal(SIGCHLD, reapchild);
- (void) signal(SIGALRM, domarkAlarmHdlr);
- (void) signal(SIGUSR1, Debug ? debug_switch : SIG_IGN);
- (void) signal(SIGPIPE, SIG_IGN);
- (void) signal(SIGXFSZ, SIG_IGN); /* do not abort if 2gig file limit is hit */
+ memset(&sigAct, 0, sizeof (sigAct));
+ sigemptyset(&sigAct.sa_mask);
+
+ sigAct.sa_handler = doDie;
+ sigaction(SIGTERM, &sigAct, NULL);
+ sigAct.sa_handler = Debug ? doDie : SIG_IGN;
+ sigaction(SIGINT, &sigAct, NULL);
+ sigaction(SIGQUIT, &sigAct, NULL);
+ sigAct.sa_handler = reapchild;
+ sigaction(SIGCHLD, &sigAct, NULL);
+ sigAct.sa_handler = domarkAlarmHdlr;
+ sigaction(SIGALRM, &sigAct, NULL);
+ sigAct.sa_handler = Debug ? debug_switch : SIG_IGN;
+ sigaction(SIGUSR1, &sigAct, NULL);
+ sigAct.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &sigAct, NULL);
+ sigaction(SIGXFSZ, &sigAct, NULL); /* do not abort if 2gig file limit is hit */
(void) alarm(TIMERINTVL);
dbgprintf("Starting.\n");