diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c --- a/sbin/reboot/reboot.c +++ b/sbin/reboot/reboot.c @@ -56,6 +56,7 @@ static uint64_t get_pageins(void); static bool dohalt; +static bool donextboot; #define E(...) do { \ if (force) { \ @@ -177,18 +178,25 @@ if (strstr(getprogname(), "halt") != NULL) { dohalt = true; howto = RB_HALT; - } else + } else if (strcmp(getprogname(), "nextboot") == 0) { + donextboot = true; + } else { howto = 0; + } Dflag = fflag = lflag = Nflag = nflag = qflag = false; while ((ch = getopt(argc, argv, "cDdek:lNnopqr")) != -1) switch(ch) { case 'c': + if (donextboot) + usage(); howto |= RB_POWERCYCLE; break; case 'D': Dflag = true; break; case 'd': + if (donextboot) + usage(); howto |= RB_DUMP; break; case 'e': @@ -202,13 +210,19 @@ kernel = optarg; break; case 'l': + if (donextboot) + usage(); lflag = true; break; case 'n': + if (donextboot) + usage(); nflag = true; howto |= RB_NOSYNC; break; case 'N': + if (donextboot) + usage(); nflag = true; Nflag = true; break; @@ -216,12 +230,18 @@ add_env(&env, "kernel_options", optarg); break; case 'p': + if (donextboot) + usage(); howto |= RB_POWEROFF; break; case 'q': + if (donextboot) + usage(); qflag = true; break; case 'r': + if (donextboot) + usage(); howto |= RB_REROOT; break; case '?': @@ -245,10 +265,6 @@ errx(1, "-r cannot be used with -c, -d, -n, or -p"); if ((howto & RB_REROOT) != 0 && kernel != NULL) errx(1, "-r and -k cannot be used together, there is no next kernel"); - if (geteuid()) { - errno = EPERM; - err(1, NULL); - } if (Dflag) { if (unlink(PATH_NEXTBOOT) != 0) @@ -256,6 +272,11 @@ exit(0); } + if (!donextboot && geteuid()) { + errno = EPERM; + err(1, NULL); + } + if (qflag) { reboot(howto); err(1, NULL); @@ -278,7 +299,11 @@ add_env(&env, "kernel", kernel); } - write_nextboot(PATH_NEXTBOOT, env, fflag); + if (env != NULL) + write_nextboot(PATH_NEXTBOOT, env, fflag); + if (donextboot) + exit (0); + /* Log the reboot. */ if (!lflag) { if ((user = getlogin()) == NULL)