Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Feb 2024 18:53:40 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 2c479548119a - main - reboot: Implement -D from nextboot
Message-ID:  <202402121853.41CIreLA030565@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=2c479548119a11058fe8947ba021fd49d4169920

commit 2c479548119a11058fe8947ba021fd49d4169920
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-02-12 18:45:29 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-02-12 18:45:29 +0000

    reboot: Implement -D from nextboot
    
    Implement -D from nextboot.sh which deletes the nextboot.conf file and
    exists.
    
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D43822
---
 sbin/reboot/reboot.8 | 12 ++++++++----
 sbin/reboot/reboot.c | 17 ++++++++++++++---
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/sbin/reboot/reboot.8 b/sbin/reboot/reboot.8
index 0a2fb91b6b0b..e53de69e97ae 100644
--- a/sbin/reboot/reboot.8
+++ b/sbin/reboot/reboot.8
@@ -36,16 +36,16 @@
 .Nd stopping and restarting the system
 .Sh SYNOPSIS
 .Nm halt
-.Op Fl flNnpq
+.Op Fl DflNnpq
 .Op Fl k Ar kernel
 .Nm
-.Op Fl cdflNnpqr
+.Op Fl cDdflNnpqr
 .Op Fl k Ar kernel
 .Nm fasthalt
-.Op Fl flNnpq
+.Op Fl DflNnpq
 .Op Fl k Ar kernel
 .Nm fastboot
-.Op Fl dflNnpq
+.Op Fl dDflNnpq
 .Op Fl k Ar kernel
 .Sh DESCRIPTION
 The
@@ -77,6 +77,10 @@ driver implements the power cycle functionality and only on hardware
 with a BMC that supports power cycling.
 Unlike power off, the amount of hardware that supports power cycling
 is small.
+.It Fl D
+Delete existing
+.Nm nextboot
+configuration and exit.
 .It Fl d
 The system is requested to create a crash dump.
 This option is
diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c
index 74f8cf01b3b7..d91fc6c97b0f 100644
--- a/sbin/reboot/reboot.c
+++ b/sbin/reboot/reboot.c
@@ -95,7 +95,7 @@ main(int argc, char *argv[])
 	struct utmpx utx;
 	const struct passwd *pw;
 	int ch, howto, i, sverrno;
-	bool fflag, lflag, nflag, qflag, Nflag;
+	bool Dflag, fflag, lflag, Nflag, nflag, qflag;
 	uint64_t pageins;
 	const char *user, *kernel = NULL;
 
@@ -104,12 +104,15 @@ main(int argc, char *argv[])
 		howto = RB_HALT;
 	} else
 		howto = 0;
-	fflag = lflag = nflag = qflag = Nflag = false;
-	while ((ch = getopt(argc, argv, "cdk:lNnpqr")) != -1)
+	Dflag = fflag = lflag = Nflag = nflag = qflag = false;
+	while ((ch = getopt(argc, argv, "cDdk:lNnpqr")) != -1)
 		switch(ch) {
 		case 'c':
 			howto |= RB_POWERCYCLE;
 			break;
+		case 'D':
+			Dflag = true;
+			break;
 		case 'd':
 			howto |= RB_DUMP;
 			break;
@@ -148,6 +151,8 @@ main(int argc, char *argv[])
 	if (argc != 0)
 		usage();
 
+	if (Dflag && ((howto & ~RB_HALT) != 0  || kernel != NULL))
+		errx(1, "cannot delete existing nextboot config and do anything else");
 	if ((howto & (RB_DUMP | RB_HALT)) == (RB_DUMP | RB_HALT))
 		errx(1, "cannot dump (-d) when halting; must reboot instead");
 	if (Nflag && (howto & RB_NOSYNC) != 0)
@@ -163,6 +168,12 @@ main(int argc, char *argv[])
 		err(1, NULL);
 	}
 
+	if (Dflag) {
+		if (unlink(PATH_NEXTBOOT) != 0)
+			err(1, "unlink %s", PATH_NEXTBOOT);
+		exit(0);
+	}
+
 	if (qflag) {
 		reboot(howto);
 		err(1, NULL);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202402121853.41CIreLA030565>