summaryrefslogtreecommitdiffstats
path: root/klogd.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-06-15 16:13:03 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-06-15 16:13:03 +0000
commit1b6350042bae11395f7717dbc10eb8658fac852a (patch)
tree5849f966af529b52f908fdbf3d90601dd9c69563 /klogd.c
parentc1b67fa602da7d75c5699f5ded875b8f77a1b913 (diff)
downloadrsyslog-1b6350042bae11395f7717dbc10eb8658fac852a.tar.gz
rsyslog-1b6350042bae11395f7717dbc10eb8658fac852a.tar.xz
rsyslog-1b6350042bae11395f7717dbc10eb8658fac852a.zip
improved signal handling in klogd
Diffstat (limited to 'klogd.c')
-rw-r--r--klogd.c67
1 files changed, 47 insertions, 20 deletions
diff --git a/klogd.c b/klogd.c
index 5e807c9b..3a82e8fa 100644
--- a/klogd.c
+++ b/klogd.c
@@ -439,7 +439,6 @@ static void CloseLogSrc(void)
void restart(int sig)
{
- signal(SIGCONT, restart);
change_state = 1;
caught_TSTP = 0;
return;
@@ -448,7 +447,6 @@ void restart(int sig)
void stop_logging(int sig)
{
- signal(SIGTSTP, stop_logging);
change_state = 1;
caught_TSTP = 1;
return;
@@ -471,10 +469,7 @@ void reload_daemon(int sig)
if ( sig == SIGUSR2 )
{
++reload_symbols;
- signal(SIGUSR2, reload_daemon);
}
- else
- signal(SIGUSR1, reload_daemon);
return;
}
@@ -936,6 +931,17 @@ static void LogProcLine(void)
}
+/* helper routine to spit out an error message and terminate
+ * klogd when setting a signal error fails.
+ */
+void sigactionErrAbort()
+{
+ fprintf(stderr, "rklogd: could net set a signal handler - terminating. Error: %s\n",
+ strerror(errno));
+ exit(1);
+}
+
+
int main(int argc, char *argv[])
{
int ch,
@@ -1065,23 +1071,44 @@ int main(int argc, char *argv[])
}
#endif
- /* Signal setups. */
- // TODO: change this all to sigaction
- for (ch= 1; ch < NSIG; ++ch)
- signal(ch, SIG_IGN);
-
- sigAct.sa_handler = stop_daemon;
+ /* Signal setups.
+ * Please note that the "original" klogd in sysklogd tries to
+ * handle SIGKILL and SIGSTOP. That does not work - but as the
+ * original klogd had no error checking, nobody ever noticed. We
+ * do now have error checking and consequently those ever-failing
+ * calls are now removed.
+ */
sigemptyset(&sigAct.sa_mask);
sigAct.sa_flags = 0;
- sigaction(SIGINT, &sigAct, NULL);
- sigaction(SIGKILL, &sigAct, NULL);
- sigaction(SIGTERM, &sigAct, NULL);
- sigaction(SIGHUP, &sigAct, NULL);
-
- signal(SIGTSTP, stop_logging);
- signal(SIGCONT, restart);
- signal(SIGUSR1, reload_daemon);
- signal(SIGUSR2, reload_daemon);
+
+ /* first, set all signals to ignore
+ * In this loop, we try blindly to ignore all signals. I am leaving
+ * intentionally out all error checking. If we can ignore the signal,
+ * that's nice, but if we can't ... well, so be it ;)
+ * RGerhards, 2007-06-15
+ */
+ sigAct.sa_handler = SIG_IGN;
+ for (ch= 1; ch < NSIG ; ++ch)
+ {
+ if(ch != SIGKILL && ch != SIGSTOP)
+ sigaction(ch, &sigAct, NULL);
+ }
+
+ /* Now specific handlers (one after another) */
+ sigAct.sa_handler = stop_daemon;
+ if(sigaction(SIGINT, &sigAct, NULL) != 0) sigactionErrAbort();
+ if(sigaction(SIGTERM, &sigAct, NULL) != 0) sigactionErrAbort();
+ if(sigaction(SIGHUP, &sigAct, NULL) != 0) sigactionErrAbort();
+
+ sigAct.sa_handler = stop_daemon;
+ if(sigaction(SIGTSTP, &sigAct, NULL) != 0) sigactionErrAbort();
+
+ sigAct.sa_handler = restart;
+ if(sigaction(SIGCONT, &sigAct, NULL) != 0) sigactionErrAbort();
+
+ sigAct.sa_handler = reload_daemon;
+ if(sigaction(SIGUSR1, &sigAct, NULL) != 0) sigactionErrAbort();
+ if(sigaction(SIGUSR2, &sigAct, NULL) != 0) sigactionErrAbort();
/* Open outputs. */