mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-21 18:27:22 +00:00
reboot: Allow this to be installed as nextboot
Allow nextboot to be a symlink link to reboot. It does everything reboot does, except doesn't actually setup the sytem to reboot and reboot. Also, don't accept the reboot args related to rebooting when in nextboot mode. Sponsored by: Netflix Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43830
This commit is contained in:
parent
91d2407702
commit
994cc83921
|
@ -56,6 +56,7 @@ static void usage(void) __dead2;
|
|||
static uint64_t get_pageins(void);
|
||||
|
||||
static bool dohalt;
|
||||
static bool donextboot;
|
||||
|
||||
#define E(...) do { \
|
||||
if (force) { \
|
||||
|
@ -163,6 +164,12 @@ add_env(char **env, const char *key, const char *value)
|
|||
free(oldenv);
|
||||
}
|
||||
|
||||
/*
|
||||
* Different options are valid for different programs.
|
||||
*/
|
||||
#define GETOPT_REBOOT "cDde:k:lNno:pqr"
|
||||
#define GETOPT_NEXTBOOT "De:k:o:"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -171,16 +178,20 @@ main(int argc, char *argv[])
|
|||
int ch, howto, i, sverrno;
|
||||
bool Dflag, fflag, lflag, Nflag, nflag, qflag;
|
||||
uint64_t pageins;
|
||||
const char *user, *kernel = NULL;
|
||||
const char *user, *kernel = NULL, *getopts = GETOPT_REBOOT;
|
||||
char *env = NULL, *v;
|
||||
|
||||
if (strstr(getprogname(), "halt") != NULL) {
|
||||
dohalt = true;
|
||||
howto = RB_HALT;
|
||||
} else
|
||||
} else if (strcmp(getprogname(), "nextboot") == 0) {
|
||||
donextboot = true;
|
||||
getopts = GETOPT_NEXTBOOT; /* Note: reboot's extra opts return '?' */
|
||||
} else {
|
||||
howto = 0;
|
||||
}
|
||||
Dflag = fflag = lflag = Nflag = nflag = qflag = false;
|
||||
while ((ch = getopt(argc, argv, "cDde:k:lNno:pqr")) != -1)
|
||||
while ((ch = getopt(argc, argv, getopts)) != -1) {
|
||||
switch(ch) {
|
||||
case 'c':
|
||||
howto |= RB_POWERCYCLE;
|
||||
|
@ -228,6 +239,8 @@ main(int argc, char *argv[])
|
|||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc != 0)
|
||||
|
@ -245,10 +258,6 @@ main(int argc, char *argv[])
|
|||
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 +265,11 @@ main(int argc, char *argv[])
|
|||
exit(0);
|
||||
}
|
||||
|
||||
if (!donextboot && geteuid() != 0) {
|
||||
errno = EPERM;
|
||||
err(1, NULL);
|
||||
}
|
||||
|
||||
if (qflag) {
|
||||
reboot(howto);
|
||||
err(1, NULL);
|
||||
|
@ -278,7 +292,11 @@ main(int argc, char *argv[])
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue