Changeset View
Changeset View
Standalone View
Standalone View
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 = Nflag = 0; | lflag = nflag = qflag = Nflag = 0; | ||||
while ((ch = getopt(argc, argv, "dk:lNnpqr")) != -1) | while ((ch = getopt(argc, argv, "cdk:lNnpqr")) != -1) | ||||
switch(ch) { | switch(ch) { | ||||
case 'c': | |||||
howto |= RB_POWERCYCLE; | |||||
break; | |||||
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; | ||||
Show All 21 Lines | while ((ch = getopt(argc, argv, "cdk:lNnpqr")) != -1) | ||||
} | } | ||||
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 (Nflag && (howto & RB_NOSYNC) != 0) | if (Nflag && (howto & RB_NOSYNC) != 0) | ||||
errx(1, "-N cannot be used with -n"); | errx(1, "-N cannot be used with -n"); | ||||
if ((howto & RB_POWEROFF) && (howto & RB_POWERCYCLE)) | |||||
errx(1, "-c and -p cannot be used together"); | |||||
if ((howto & RB_REROOT) != 0 && howto != RB_REROOT) | if ((howto & RB_REROOT) != 0 && howto != RB_REROOT) | ||||
errx(1, "-r cannot be used with -d, -n, or -p"); | errx(1, "-r cannot be used with -c, -d, -n, or -p"); | ||||
jtl: Suggest adding a similar check for -p and -c used together. | |||||
Done Inline ActionsGood idea. imp: Good idea. | |||||
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 17 Lines | 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) { | } else if (howto & RB_REROOT) { | ||||
openlog("reroot", 0, LOG_AUTH | LOG_CONS); | openlog("reroot", 0, LOG_AUTH | LOG_CONS); | ||||
syslog(LOG_CRIT, "rerooted by %s", user); | syslog(LOG_CRIT, "rerooted by %s", user); | ||||
} else if (howto & RB_POWEROFF) { | |||||
openlog("reboot", 0, LOG_AUTH | LOG_CONS); | |||||
syslog(LOG_CRIT, "powered off by %s", user); | |||||
} else if (howto & RB_POWERCYCLE) { | |||||
openlog("reboot", 0, LOG_AUTH | LOG_CONS); | |||||
syslog(LOG_CRIT, "power cycled 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 20 Lines • Show All 108 Lines • Show Last 20 Lines |
Suggest adding a similar check for -p and -c used together.