Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Oct 2016 13:41:29 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r306807 - head/sbin/init
Message-ID:  <201610071341.u97DfTY5047152@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Fri Oct  7 13:41:28 2016
New Revision: 306807
URL: https://svnweb.freebsd.org/changeset/base/306807

Log:
  When making a pause after detecting hard kill of the single-user
  shell, ensure that we do sleep for at least the specified time, in
  presence of signals.
  
  Interrupted sleep(3) is followed by _exit(), which might cause 'Going
  nowhere without my init' panic if init(8) exits before the reboot(2)
  really started, or before SIGTSTP stopped init(8) (both events are
  initiated by the parallel reboot(8) operation).
  
  I do not see other calls to sleep(STALL_TIMEOUT) as having the same
  disasterous consequences and kept them as is until the similar change
  is proven required.
  
  Reported and tested by:	Andy Farkas <chuzzwassa@gmail.com>
  Sponsored by:	The FreeBSD Foundation
  MFC after:	3 weeks

Modified:
  head/sbin/init/init.c

Modified: head/sbin/init/init.c
==============================================================================
--- head/sbin/init/init.c	Fri Oct  7 12:57:35 2016	(r306806)
+++ head/sbin/init/init.c	Fri Oct  7 13:41:28 2016	(r306807)
@@ -870,6 +870,7 @@ single_user(void)
 	sigset_t mask;
 	const char *shell;
 	char *argv[2];
+	struct timeval tv, tn;
 #ifdef SECURE
 	struct ttyent *typ;
 	struct passwd *pp;
@@ -1002,7 +1003,14 @@ single_user(void)
 			 *  reboot(8) killed shell?
 			 */
 			warning("single user shell terminated.");
-			sleep(STALL_TIMEOUT);
+			gettimeofday(&tv, NULL);
+			tn = tv;
+			tv.tv_sec += STALL_TIMEOUT;
+			while (tv.tv_sec > tn.tv_sec || (tv.tv_sec ==
+			    tn.tv_sec && tv.tv_usec > tn.tv_usec)) {
+				sleep(1);
+				gettimeofday(&tn, NULL);
+			}
 			_exit(0);
 		} else {
 			warning("single user shell terminated, restarting");



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