summaryrefslogtreecommitdiffstats
path: root/sbin/reboot/reboot.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/reboot/reboot.c')
-rw-r--r--sbin/reboot/reboot.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c
index 6d590ac..961ba41 100644
--- a/sbin/reboot/reboot.c
+++ b/sbin/reboot/reboot.c
@@ -77,7 +77,7 @@ main(int argc, char *argv[])
} else
howto = 0;
lflag = nflag = qflag = Nflag = 0;
- while ((ch = getopt(argc, argv, "dk:lNnpq")) != -1)
+ while ((ch = getopt(argc, argv, "dk:lNnpqr")) != -1)
switch(ch) {
case 'd':
howto |= RB_DUMP;
@@ -102,6 +102,9 @@ main(int argc, char *argv[])
case 'q':
qflag = 1;
break;
+ case 'r':
+ howto |= RB_REROOT;
+ break;
case '?':
default:
usage();
@@ -113,6 +116,8 @@ main(int argc, char *argv[])
errx(1, "cannot dump (-d) when halting; must reboot instead");
if (Nflag && (howto & RB_NOSYNC) != 0)
errx(1, "-N cannot be used with -n");
+ if ((howto & RB_REROOT) != 0 && howto != RB_REROOT)
+ errx(1, "-r cannot be used with -d, -n, or -p");
if (geteuid()) {
errno = EPERM;
err(1, NULL);
@@ -143,6 +148,9 @@ main(int argc, char *argv[])
if (dohalt) {
openlog("halt", 0, LOG_AUTH | LOG_CONS);
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 {
openlog("reboot", 0, LOG_AUTH | LOG_CONS);
syslog(LOG_CRIT, "rebooted by %s", user);
@@ -176,6 +184,16 @@ main(int argc, char *argv[])
*/
(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. */
if (kill(1, SIGTSTP) == -1)
err(1, "SIGTSTP init");
OpenPOWER on IntegriCloud