Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Jan 2011 08:18:58 +0000 (UTC)
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r217439 - stable/8/sbin/hastd
Message-ID:  <201101150818.p0F8IwAN017938@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pjd
Date: Sat Jan 15 08:18:58 2011
New Revision: 217439
URL: http://svn.freebsd.org/changeset/base/217439

Log:
  MFC r217307,r217308,r217312:
  
  r217307:
  
  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
  
  r217308:
  
  Add a note that when custom signal handler is installed for a signal,
  signal action is restored to default in child after fork(2).
  In this case there is no need to do anything with dummy SIGCHLD handler,
  because after fork(2) it will be automatically reverted to SIG_IGN.
  
  Obtained from:	Wheel Systems Sp. z o.o. http://www.wheelsystems.com
  
  r217312:
  
  execve(2), not fork(2) resets signal handler to the default value (if it isn't
  ignored). Correct comment talking about that.
  
  Pointed out by:	kib

Modified:
  stable/8/sbin/hastd/hastd.c
  stable/8/sbin/hastd/hooks.c
Directory Properties:
  stable/8/sbin/hastd/   (props changed)

Modified: stable/8/sbin/hastd/hastd.c
==============================================================================
--- stable/8/sbin/hastd/hastd.c	Sat Jan 15 03:06:03 2011	(r217438)
+++ stable/8/sbin/hastd/hastd.c	Sat Jan 15 08:18:58 2011	(r217439)
@@ -754,10 +754,18 @@ main(int argc, char *argv[])
 	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);

Modified: stable/8/sbin/hastd/hooks.c
==============================================================================
--- stable/8/sbin/hastd/hooks.c	Sat Jan 15 03:06:03 2011	(r217438)
+++ stable/8/sbin/hastd/hooks.c	Sat Jan 15 08:18:58 2011	(r217439)
@@ -372,6 +372,11 @@ hook_execv(const char *path, va_list ap)
 		descriptors();
 		PJDLOG_VERIFY(sigemptyset(&mask) == 0);
 		PJDLOG_VERIFY(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
+		/*
+		 * Dummy handler set for SIGCHLD in the parent will be restored
+		 * to SIG_IGN on execv(3) below, so there is no need to do
+		 * anything with it.
+		 */
 		execv(path, args);
 		pjdlog_errno(LOG_ERR, "Unable to execute %s", path);
 		exit(EX_SOFTWARE);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101150818.p0F8IwAN017938>