diff options
author | wes <wes@FreeBSD.org> | 2002-04-26 07:31:04 +0000 |
---|---|---|
committer | wes <wes@FreeBSD.org> | 2002-04-26 07:31:04 +0000 |
commit | 9bf40bea60a51889f77b8f5c8128b2bebe1a3284 (patch) | |
tree | 7ead246584ad34442c705cb33fc0bfa686914287 /sbin/reboot/reboot.c | |
parent | a83271f3cb64d931c0f89f438d35104acfd34863 (diff) | |
download | FreeBSD-src-9bf40bea60a51889f77b8f5c8128b2bebe1a3284.zip FreeBSD-src-9bf40bea60a51889f77b8f5c8128b2bebe1a3284.tar.gz |
Add a -k option to reboot to specify the kernel to boot next time
around. If the kernel boots successfully, the record of this kernel
is erased, it is intended to be a one-shot option for testing
kernels.
This could be improved by having the loader remove the record of
the next kernel to boot, it is currently removed in /etc/rc immediately
after disks are mounted r/w.
I'd like to MFC this before the 4.6 freeze unless there is violent
objection.
Reviewed by: Several on IRC
MFC after: 4 days
Diffstat (limited to 'sbin/reboot/reboot.c')
-rw-r--r-- | sbin/reboot/reboot.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c index 61f971d..be8911f 100644 --- a/sbin/reboot/reboot.c +++ b/sbin/reboot/reboot.c @@ -51,6 +51,7 @@ static const char rcsid[] = #include <signal.h> #include <err.h> #include <errno.h> +#include <fcntl.h> #include <libutil.h> #include <pwd.h> #include <syslog.h> @@ -68,9 +69,9 @@ int main(int argc, char *argv[]) { struct passwd *pw; - int ch, howto, i, lflag, nflag, qflag, pflag, sverrno; + int ch, howto, i, fd, kflag, lflag, nflag, qflag, pflag, sverrno; u_int pageins; - char *p; + char *kernel, *p; const char *user; if (strstr((p = rindex(*argv, '/')) ? p + 1 : *argv, "halt")) { @@ -78,12 +79,16 @@ main(int argc, char *argv[]) howto = RB_HALT; } else howto = 0; - lflag = nflag = qflag = 0; - while ((ch = getopt(argc, argv, "dlnpq")) != -1) + kflag = lflag = nflag = qflag = 0; + while ((ch = getopt(argc, argv, "dk:lnpq")) != -1) switch(ch) { case 'd': howto |= RB_DUMP; break; + case 'k': + kflag = 1; + kernel = optarg; + break; case 'l': lflag = 1; break; @@ -117,6 +122,16 @@ main(int argc, char *argv[]) err(1, NULL); } + if (kflag) { + fd = open("/boot/nextkernel", O_WRONLY | O_CREAT, 0444); + if (fd > -1) { + (void)write(fd, "kernel=\"", 8L); + (void)write(fd, kernel, strlen(kernel)); + (void)write(fd, "\"\n", 2); + close(fd); + } + } + /* Log the reboot. */ if (!lflag) { if ((user = getlogin()) == NULL) @@ -195,7 +210,7 @@ restart: void usage() { - (void)fprintf(stderr, "usage: %s [-dnpq]\n", + (void)fprintf(stderr, "usage: %s [-dnpq] [-k kernel]\n", dohalt ? "halt" : "reboot"); exit(1); } |