Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2015-04-15 23:55:14 +0200
committerArthur de Jong <arthur@arthurdejong.org>2015-04-16 00:00:34 +0200
commit530cc24c83dd5d2d347acb40d64c3ae06a43a293 (patch)
tree7200344499ba066d8215c2847eb70f301e1f306d
parent16fd8c615153eb8851c009b6b7cc6f836baf6620 (diff)
Avoid signal race condition on start-up
This only restores the signal mask after signal handlers are in place and the daemon has completely daemonised to avoid a race condition in the start-up phase of nslcd where a signal could be sent to nslcd causing it to quit or fail to write information to the parent process.
-rw-r--r--nslcd/daemonize.c2
-rw-r--r--nslcd/nslcd.c5
2 files changed, 4 insertions, 3 deletions
diff --git a/nslcd/daemonize.c b/nslcd/daemonize.c
index 60f2d91..d11d358 100644
--- a/nslcd/daemonize.c
+++ b/nslcd/daemonize.c
@@ -89,7 +89,7 @@ static int read_response(int fd, char *buffer, size_t bufsz)
return r;
}
-/* ihe process calling daemonize_daemon() will end up here on success */
+/* The parent process calling daemonize_daemon() will end up here on success */
static int wait_for_response(int fd)
{
int i, l, rc;
diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c
index f765b9c..469793a 100644
--- a/nslcd/nslcd.c
+++ b/nslcd/nslcd.c
@@ -838,8 +838,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
- pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
- /* install signalhandlers for some signals */
+ /* install signal handlers for some signals */
install_sighandler(SIGHUP, sig_handler);
install_sighandler(SIGINT, sig_handler);
install_sighandler(SIGQUIT, sig_handler);
@@ -850,6 +849,8 @@ int main(int argc, char *argv[])
install_sighandler(SIGUSR2, SIG_IGN);
/* signal the starting process to exit because we can provide services now */
daemonize_ready(EXIT_SUCCESS, NULL);
+ /* enable receiving of signals */
+ pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
/* wait until we received a signal */
while ((nslcd_receivedsignal == 0) || (nslcd_receivedsignal == SIGUSR1))
{