Changeset View
Changeset View
Standalone View
Standalone View
sbin/reboot/reboot.c
Show All 37 Lines | |||||
#ifndef lint | #ifndef lint | ||||
static char sccsid[] = "@(#)reboot.c 8.1 (Berkeley) 6/5/93"; | static char sccsid[] = "@(#)reboot.c 8.1 (Berkeley) 6/5/93"; | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#endif | #endif | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/reboot.h> | |||||
#include <sys/time.h> | |||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/boottrace.h> | |||||
#include <sys/reboot.h> | |||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/time.h> | |||||
#include <signal.h> | #include <signal.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <pwd.h> | #include <pwd.h> | ||||
#include <syslog.h> | #include <syslog.h> | ||||
#include <stdarg.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <utmpx.h> | #include <utmpx.h> | ||||
static void usage(void); | static void usage(void); | ||||
static u_int get_pageins(void); | static u_int get_pageins(void); | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
if (howto & RB_REROOT) { | if (howto & RB_REROOT) { | ||||
if (kill(1, SIGEMT) == -1) | if (kill(1, SIGEMT) == -1) | ||||
err(1, "SIGEMT init"); | err(1, "SIGEMT init"); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* Just stop init -- if we fail, we'll restart it. */ | /* Just stop init -- if we fail, we'll restart it. */ | ||||
BOOTTRACE("SIGTSTP to init(8)..."); | |||||
if (kill(1, SIGTSTP) == -1) | if (kill(1, SIGTSTP) == -1) | ||||
err(1, "SIGTSTP init"); | err(1, "SIGTSTP init"); | ||||
/* Send a SIGTERM first, a chance to save the buffers. */ | /* Send a SIGTERM first, a chance to save the buffers. */ | ||||
BOOTTRACE("SIGTERM to all other processes..."); | |||||
if (kill(-1, SIGTERM) == -1 && errno != ESRCH) | if (kill(-1, SIGTERM) == -1 && errno != ESRCH) | ||||
err(1, "SIGTERM processes"); | err(1, "SIGTERM processes"); | ||||
/* | /* | ||||
* After the processes receive the signal, start the rest of the | * After the processes receive the signal, start the rest of the | ||||
* buffers on their way. Wait 5 seconds between the SIGTERM and | * buffers on their way. Wait 5 seconds between the SIGTERM and | ||||
* the SIGKILL to give everybody a chance. If there is a lot of | * the SIGKILL to give everybody a chance. If there is a lot of | ||||
* paging activity then wait longer, up to a maximum of approx | * paging activity then wait longer, up to a maximum of approx | ||||
* 60 seconds. | * 60 seconds. | ||||
*/ | */ | ||||
sleep(2); | sleep(2); | ||||
for (i = 0; i < 20; i++) { | for (i = 0; i < 20; i++) { | ||||
pageins = get_pageins(); | pageins = get_pageins(); | ||||
if (!nflag) | if (!nflag) | ||||
sync(); | sync(); | ||||
sleep(3); | sleep(3); | ||||
if (get_pageins() == pageins) | if (get_pageins() == pageins) | ||||
break; | break; | ||||
} | } | ||||
for (i = 1;; ++i) { | for (i = 1;; ++i) { | ||||
BOOTTRACE("SIGKILL to all other processes(%d)...", i); | |||||
if (kill(-1, SIGKILL) == -1) { | if (kill(-1, SIGKILL) == -1) { | ||||
if (errno == ESRCH) | if (errno == ESRCH) | ||||
break; | break; | ||||
goto restart; | goto restart; | ||||
} | } | ||||
if (i > 5) { | if (i > 5) { | ||||
(void)fprintf(stderr, | (void)fprintf(stderr, | ||||
"WARNING: some process(es) wouldn't die\n"); | "WARNING: some process(es) wouldn't die\n"); | ||||
break; | break; | ||||
} | } | ||||
(void)sleep(2 * i); | (void)sleep(2 * i); | ||||
} | } | ||||
reboot(howto); | reboot(howto); | ||||
/* FALLTHROUGH */ | /* FALLTHROUGH */ | ||||
restart: | restart: | ||||
BOOTTRACE("SIGHUP to init(8)..."); | |||||
sverrno = errno; | sverrno = errno; | ||||
errx(1, "%s%s", kill(1, SIGHUP) == -1 ? "(can't restart init): " : "", | errx(1, "%s%s", kill(1, SIGHUP) == -1 ? "(can't restart init): " : "", | ||||
strerror(sverrno)); | strerror(sverrno)); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
Show All 22 Lines |