diff options
author | 2017-08-22 00:30:16 +0000 | |
---|---|---|
committer | 2017-08-22 00:30:16 +0000 | |
commit | 3dbceb111e53f1214fca60a5e698bd73cba58bd1 (patch) | |
tree | cc1407fb6e1ca69e069c14ef8c9e67c10eefd90d | |
parent | Add some buffercache docs (diff) | |
download | wireguard-openbsd-3dbceb111e53f1214fca60a5e698bd73cba58bd1.tar.xz wireguard-openbsd-3dbceb111e53f1214fca60a5e698bd73cba58bd1.zip |
reboot: don't wait for processes to die if there are none
If processes are already dead, reduce wait times between SIGTERM and
SIGKILL and wait time after SIGKILL. The reboot syscall will cause
another sync later on, therefore the long wait times are not necessary
for disk i/o, either.
"makes sense" deraadt@
-rw-r--r-- | sbin/reboot/reboot.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c index dd85d0d9c8c..0e215c2b93a 100644 --- a/sbin/reboot/reboot.c +++ b/sbin/reboot/reboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: reboot.c,v 1.37 2017/06/16 06:46:54 natano Exp $ */ +/* $OpenBSD: reboot.c,v 1.38 2017/08/22 00:30:16 sf Exp $ */ /* $NetBSD: reboot.c,v 1.8 1995/10/05 05:36:22 mycroft Exp $ */ /* @@ -57,6 +57,17 @@ int dohalt; #define _PATH_RC "/etc/rc" +static void +sleep_while_procs(int seconds) +{ + while (seconds > 0) { + if (kill(-1, 0) == -1 && errno == ESRCH) + return; + sleep(1); + seconds--; + } +} + int main(int argc, char *argv[]) { @@ -232,10 +243,10 @@ main(int argc, char *argv[]) * buffers on their way. Wait 5 seconds between the SIGTERM and * the SIGKILL to give everybody a chance. */ - sleep(2); + sleep_while_procs(2); if (!nflag) sync(); - sleep(3); + sleep_while_procs(3); for (i = 1;; ++i) { if (kill(-1, SIGKILL) == -1) { @@ -247,7 +258,7 @@ main(int argc, char *argv[]) warnx("WARNING: some process(es) wouldn't die"); break; } - (void)sleep(2 * i); + sleep_while_procs(2 * i); } reboot(howto); |