Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/reboot/reboot.c
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
const char *user, *kernel = NULL; | const char *user, *kernel = NULL; | ||||
if (strcmp(getprogname(), "halt") == 0) { | if (strcmp(getprogname(), "halt") == 0) { | ||||
dohalt = 1; | dohalt = 1; | ||||
howto = RB_HALT; | howto = RB_HALT; | ||||
} else | } else | ||||
howto = 0; | howto = 0; | ||||
lflag = nflag = qflag = 0; | lflag = nflag = qflag = 0; | ||||
while ((ch = getopt(argc, argv, "dk:lnpq")) != -1) | while ((ch = getopt(argc, argv, "dk:lnpqr")) != -1) | ||||
switch(ch) { | switch(ch) { | ||||
case 'd': | case 'd': | ||||
howto |= RB_DUMP; | howto |= RB_DUMP; | ||||
break; | break; | ||||
case 'k': | case 'k': | ||||
kernel = optarg; | kernel = optarg; | ||||
break; | break; | ||||
case 'l': | case 'l': | ||||
lflag = 1; | lflag = 1; | ||||
break; | break; | ||||
case 'n': | case 'n': | ||||
nflag = 1; | nflag = 1; | ||||
howto |= RB_NOSYNC; | howto |= RB_NOSYNC; | ||||
break; | break; | ||||
case 'p': | case 'p': | ||||
howto |= RB_POWEROFF; | howto |= RB_POWEROFF; | ||||
break; | break; | ||||
case 'q': | case 'q': | ||||
qflag = 1; | qflag = 1; | ||||
break; | break; | ||||
case 'r': | |||||
howto |= RB_REROOT; | |||||
break; | |||||
case '?': | case '?': | ||||
default: | default: | ||||
usage(); | usage(); | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
if ((howto & (RB_DUMP | RB_HALT)) == (RB_DUMP | RB_HALT)) | if ((howto & (RB_DUMP | RB_HALT)) == (RB_DUMP | RB_HALT)) | ||||
errx(1, "cannot dump (-d) when halting; must reboot instead"); | errx(1, "cannot dump (-d) when halting; must reboot instead"); | ||||
if ((howto & RB_REROOT) != 0 && howto != RB_REROOT) | |||||
errx(1, "-r cannot be used with -d, -n, or -p"); | |||||
if (geteuid()) { | if (geteuid()) { | ||||
errno = EPERM; | errno = EPERM; | ||||
err(1, NULL); | err(1, NULL); | ||||
} | } | ||||
if (qflag) { | if (qflag) { | ||||
reboot(howto); | reboot(howto); | ||||
err(1, NULL); | err(1, NULL); | ||||
Show All 14 Lines | main(int argc, char *argv[]) | ||||
/* Log the reboot. */ | /* Log the reboot. */ | ||||
if (!lflag) { | if (!lflag) { | ||||
if ((user = getlogin()) == NULL) | if ((user = getlogin()) == NULL) | ||||
user = (pw = getpwuid(getuid())) ? | user = (pw = getpwuid(getuid())) ? | ||||
pw->pw_name : "???"; | pw->pw_name : "???"; | ||||
if (dohalt) { | if (dohalt) { | ||||
openlog("halt", 0, LOG_AUTH | LOG_CONS); | openlog("halt", 0, LOG_AUTH | LOG_CONS); | ||||
syslog(LOG_CRIT, "halted by %s", user); | syslog(LOG_CRIT, "halted by %s", user); | ||||
} else if (howto & RB_REROOT) { | |||||
openlog("reroot", 0, LOG_AUTH | LOG_CONS); | |||||
syslog(LOG_CRIT, "rerooted by %s", user); | |||||
} else { | } else { | ||||
openlog("reboot", 0, LOG_AUTH | LOG_CONS); | openlog("reboot", 0, LOG_AUTH | LOG_CONS); | ||||
syslog(LOG_CRIT, "rebooted by %s", user); | syslog(LOG_CRIT, "rebooted by %s", user); | ||||
} | } | ||||
} | } | ||||
utx.ut_type = SHUTDOWN_TIME; | utx.ut_type = SHUTDOWN_TIME; | ||||
gettimeofday(&utx.ut_tv, NULL); | gettimeofday(&utx.ut_tv, NULL); | ||||
pututxline(&utx); | pututxline(&utx); | ||||
Show All 16 Lines | main(int argc, char *argv[]) | ||||
(void)signal(SIGTERM, SIG_IGN); | (void)signal(SIGTERM, SIG_IGN); | ||||
(void)signal(SIGTSTP, SIG_IGN); | (void)signal(SIGTSTP, SIG_IGN); | ||||
/* | /* | ||||
* If we're running in a pipeline, we don't want to die | * If we're running in a pipeline, we don't want to die | ||||
* after killing whatever we're writing to. | * after killing whatever we're writing to. | ||||
*/ | */ | ||||
(void)signal(SIGPIPE, SIG_IGN); | (void)signal(SIGPIPE, SIG_IGN); | ||||
/* | |||||
* Only init(8) can perform rerooting. | |||||
*/ | |||||
if (howto & RB_REROOT) { | |||||
if (kill(1, SIGEMT) == -1) | |||||
err(1, "SIGEMT init"); | |||||
return (0); | |||||
} | |||||
/* Just stop init -- if we fail, we'll restart it. */ | /* Just stop init -- if we fail, we'll restart it. */ | ||||
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. */ | ||||
if (kill(-1, SIGTERM) == -1 && errno != ESRCH) | if (kill(-1, SIGTERM) == -1 && errno != ESRCH) | ||||
err(1, "SIGTERM processes"); | err(1, "SIGTERM processes"); | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |