Make halt and reboot wait up to 32 seconds after kill(-1, SIGTERM), but

check at 3 second intervals if any are left.
This will help slow machines to cleanly shut down X servers (to make the
console visible), databases, or Usenet news servers.
This commit is contained in:
is 1998-07-03 13:59:56 +00:00
parent d6343652c5
commit 25718b8405
2 changed files with 31 additions and 8 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: reboot.8,v 1.9 1998/06/06 21:05:41 thorpej Exp $
.\" $NetBSD: reboot.8,v 1.10 1998/07/03 13:59:56 is Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -52,8 +52,8 @@ The
and
.Nm
utilities flush the file system cache to disk, send all running processes
a SIGTERM (and subsequently a SIGKILL) and, respectively, halt or restart
the system.
a SIGTERM, wait up to 30 seconds for them to die, send a SIGKILL to the
survivors and, respectively, halt or restart the system.
The action is logged, including entering a shutdown record into the login
accounting file.
.Pp
@ -90,6 +90,13 @@ users advance warning of their impending doom.
.Xr boot 8 ,
.Xr shutdown 8 ,
.Xr sync 8
.Sh BUGS
The single user shell will ignore the SIGTERM signal.
To avoid waiting for the timeout when
rebooting or halting from the single user shell, you have to
.Ic exec reboot
or
.Ic exec halt .
.Sh HISTORY
A
.Nm

View File

@ -1,4 +1,4 @@
/* $NetBSD: reboot.c,v 1.19 1998/06/06 21:05:41 thorpej Exp $ */
/* $NetBSD: reboot.c,v 1.20 1998/07/03 13:59:56 is Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@ -44,7 +44,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1993\n"
#if 0
static char sccsid[] = "@(#)reboot.c 8.1 (Berkeley) 6/5/93";
#else
__RCSID("$NetBSD: reboot.c,v 1.19 1998/06/06 21:05:41 thorpej Exp $");
__RCSID("$NetBSD: reboot.c,v 1.20 1998/07/03 13:59:56 is Exp $");
#endif
#endif /* not lint */
@ -182,14 +182,30 @@ main(argc, argv)
/*
* After the processes receive the signal, start the rest of the
* buffers on their way. Wait 5 seconds between the SIGTERM and
* the SIGKILL to give everybody a chance.
* buffers on their way.
*/
sleep(2);
if (!nflag)
sync();
sleep(3);
/*
* Wait for up to 30 seconds for processes that need a long
* time to shut down (e.g., X servers on old slow notebook PCs with
* only 8 MB of RAM and a slow disk; or databases), but probe at
* 3 second intervals and continue immediately if none are left.
*/
for (i=0; i<10; ++i) {
if (kill(-1, 0) == -1) {
if (errno == ESRCH)
break;
goto restart;
}
sleep(3);
}
/*
* They've had their chance. SIGKILL the remaining processes.
*/
for (i = 1;; ++i) {
if (kill(-1, SIGKILL) == -1) {
if (errno == ESRCH)