From nobody Mon Feb 12 18:53:38 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TYYWl0vKVz5BMcP; Mon, 12 Feb 2024 18:53:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TYYWk5DF8z4mF8; Mon, 12 Feb 2024 18:53:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707764018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9++syLeivXcZyoQ2rrn8xYNTk+vGI88aoJQ+R1tkrFw=; b=mRJI8AxvmFN5dl+TUi2A0tpVayhKQS0m38GK1LmCaK3mGVFvDhs3zXGDLiuQ6RDxr5O/nv Z0MJ3DACLi3l0iIupGaYk7H2KAnyERD1C4TtkgbwEmsSlUUGEaURgYsodOuuwNKi9oriFY 5FuYHGRFuq0zpdoMXId5fzKwG6vIrNKCQBJKkjdQSjw4QOp+V9GfO5phYMe5wDuVIlZ5rN bRGKlEjpfZqauMrHQ0uKGzE9UhfKdnz2IFPK88UR55LgLGceDrNyP/u5tAGSavzlf6cv9C qH0D4/LG+9Tdkk+HQEatE/VlPU8TPYb5GRxH3+CYOZbuLvxjIqtzw4VSnbuwbA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707764018; a=rsa-sha256; cv=none; b=SI4GgIMzT4dS9CPArabSszFioSN5iQ+Gjtgt/o0MXuG6hMrJw3ibOj/a6oZb2mZ6yxkUK/ HyI3NNdqexFkIamSgRYCy0JPoV32TyyyTDrqJuian+sWk0zOhoQ4gHrn4CnwL0X2gTybL9 +CIJtTmiSPES5Pym7saO95bw6Qhz6oT6qSYPvze61wnfMuzvuzqCqye56d89DJmvbaXe/e qAjMaLlKugqfsbDEUUHRxbPEup9sCzCoqSJMdN4VDw5wcLiltjo7nrNYXzhwKr/4BtXQwl ivKZFdFvMtbCy8UqFELN/kkZVqyoATAewcQewhAaYJ6aHdywNu1FaYAQhVT4Vg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707764018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9++syLeivXcZyoQ2rrn8xYNTk+vGI88aoJQ+R1tkrFw=; b=U0c/LV1wFKnZRoGMsXb7BXE0IFlMiW0G5ALjNp6lEVqxoG0AFsWR58XWbOK0A6Ven8+3Qc QOygXt60L1sVuWXROF/+84qIhEp42fCRuQ9Kdvh5J3ESGP/LlTe6vq5YwVKbafYb++9bzQ VLfVtjqfmoRHFYJY/PpiEWbhUaryt3wO8caikrq8HGFDbEPDA5LzSCeoacs5tJIhYQFwJg +K07c6Xa59112aA0TFPjXgVBRvl7pOOGUVf53Yw5Ni20NsCLAAW9UYlESYJ9qFbM51hV/M b8Kf5i7LdnT1YfzpFJx4yrq7dAkRNYg7TPkvMRVgVTGeU/ruNSsrvPzy558Dhw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TYYWk4KN8zjQY; Mon, 12 Feb 2024 18:53:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41CIrcQu030465; Mon, 12 Feb 2024 18:53:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41CIrcrj030462; Mon, 12 Feb 2024 18:53:38 GMT (envelope-from git) Date: Mon, 12 Feb 2024 18:53:38 GMT Message-Id: <202402121853.41CIrcrj030462@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 7cb1a0e6e064 - main - reboot: Don't reboot if the next kernel isn't there List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7cb1a0e6e0643cb80308f45e2cce2d127ada3c8f Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=7cb1a0e6e0643cb80308f45e2cce2d127ada3c8f commit 7cb1a0e6e0643cb80308f45e2cce2d127ada3c8f Author: Warner Losh AuthorDate: 2024-02-12 18:45:01 +0000 Commit: Warner Losh CommitDate: 2024-02-12 18:45:01 +0000 reboot: Don't reboot if the next kernel isn't there reboot -k garbage won't boot garbage unless /boot/garbage/kernel is there. Refuse to reboot if it is missing, though allow -f to force it for special-use cases. This is in keeping with nextboot.sh. Sponsored by: Netflix Reviewed by: kevans, kib, markj, emaste Differential Revision: https://reviews.freebsd.org/D43802 --- sbin/reboot/reboot.8 | 33 +++++++++++++++++++-------------- sbin/reboot/reboot.c | 21 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/sbin/reboot/reboot.8 b/sbin/reboot/reboot.8 index e9a23ef84d69..0a2fb91b6b0b 100644 --- a/sbin/reboot/reboot.8 +++ b/sbin/reboot/reboot.8 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 20, 2017 +.Dd February 8, 2024 .Dt REBOOT 8 .Os .Sh NAME @@ -36,16 +36,16 @@ .Nd stopping and restarting the system .Sh SYNOPSIS .Nm halt -.Op Fl lNnpq +.Op Fl flNnpq .Op Fl k Ar kernel .Nm -.Op Fl cdlNnpqr +.Op Fl cdflNnpqr .Op Fl k Ar kernel .Nm fasthalt -.Op Fl lNnpq +.Op Fl flNnpq .Op Fl k Ar kernel .Nm fastboot -.Op Fl dlNnpq +.Op Fl dflNnpq .Op Fl k Ar kernel .Sh DESCRIPTION The @@ -83,17 +83,22 @@ This option is supported only when rebooting, and it has no effect unless a dump device has previously been specified with .Xr dumpon 8 . -.It Fl k Ar kernel -Boot the specified -.Ar kernel +.It Fl k Ar kname +Boot the specified kernel +.Ar kname on the next system boot. -If the kernel boots successfully, the +This is a one-shot option, the .Em default -kernel will be booted on successive boots, this is a one-shot option. -If the boot fails, the system will continue attempting to boot -.Ar kernel -until the boot process is interrupted and a valid kernel booted. -This may change in the future. +kernel will be booted on successive boots. +No +.Nm reboot +or +.Nm halt +will be performed if +.Em /boot/kname/kernel +does not exist unless the +.Fl f +flag is specified. .It Fl l The halt or reboot is .Em not diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c index 7dcebef69b85..4eb5e8590589 100644 --- a/sbin/reboot/reboot.c +++ b/sbin/reboot/reboot.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -59,7 +60,7 @@ main(int argc, char *argv[]) struct utmpx utx; const struct passwd *pw; int ch, howto, i, fd, sverrno; - bool lflag, nflag, qflag, Nflag; + bool fflag, lflag, nflag, qflag, Nflag; uint64_t pageins; const char *user, *kernel = NULL; @@ -68,7 +69,7 @@ main(int argc, char *argv[]) howto = RB_HALT; } else howto = 0; - lflag = nflag = qflag = Nflag = false; + fflag = lflag = nflag = qflag = Nflag = false; while ((ch = getopt(argc, argv, "cdk:lNnpqr")) != -1) switch(ch) { case 'c': @@ -77,6 +78,9 @@ main(int argc, char *argv[]) case 'd': howto |= RB_DUMP; break; + case 'f': + fflag = true; + break; case 'k': kernel = optarg; break; @@ -130,6 +134,19 @@ main(int argc, char *argv[]) } if (kernel != NULL) { + if (!fflag) { + char *k; + struct stat sb; + + asprintf(&k, "/boot/%s/kernel", kernel); + if (k == NULL) + errx(1, "No memory to check %s", kernel); + if (stat(k, &sb) != 0) + err(1, "stat %s", k); + if (!S_ISREG(sb.st_mode)) + errx(1, "%s is not a file", k); + free(k); + } fd = open("/boot/nextboot.conf", O_WRONLY | O_CREAT | O_TRUNC, 0444); if (fd > -1) {