From 9cc97e5803c14fb724768228347c997bfad4cada Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Wed, 12 Jan 2011 14:35:29 +0000 Subject: [PATCH] Install default signal handlers before masking signals we want to handle. It is possible that the parent process ignores some of them and sigtimedwait() will never see them, eventhough they are masked. The most common situation for this to happen is boot process where init(8) ignores SIGHUP before starting to execute /etc/rc. This in turn caused hastd(8) to ignore SIGHUP. Reported by: trasz Obtained from: Wheel Systems Sp. z o.o. http://www.wheelsystems.com MFC after: 3 days --- sbin/hastd/hastd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sbin/hastd/hastd.c b/sbin/hastd/hastd.c index 4cae97362a54..3ecd9c23991e 100644 --- a/sbin/hastd/hastd.c +++ b/sbin/hastd/hastd.c @@ -753,11 +753,19 @@ main(int argc, char *argv[]) cfg = yy_config_parse(cfgpath, true); assert(cfg != NULL); + /* + * Restore default actions for interesting signals in case parent + * process (like init(8)) decided to ignore some of them (like SIGHUP). + */ + PJDLOG_VERIFY(signal(SIGHUP, SIG_DFL) != SIG_ERR); + PJDLOG_VERIFY(signal(SIGINT, SIG_DFL) != SIG_ERR); + PJDLOG_VERIFY(signal(SIGTERM, SIG_DFL) != SIG_ERR); /* * Because SIGCHLD is ignored by default, setup dummy handler for it, * so we can mask it. */ PJDLOG_VERIFY(signal(SIGCHLD, dummy_sighandler) != SIG_ERR); + PJDLOG_VERIFY(sigemptyset(&mask) == 0); PJDLOG_VERIFY(sigaddset(&mask, SIGHUP) == 0); PJDLOG_VERIFY(sigaddset(&mask, SIGINT) == 0);