From nobody Mon Feb 12 18:53:46 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 4TYYWt6QB6z5BMg7; Mon, 12 Feb 2024 18:53:46 +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 4TYYWt4rCsz4mXF; Mon, 12 Feb 2024 18:53:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707764026; 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=NlIj1shqCcq5V1/Llk2BCsFjf/+Fw7p6gFLe1OTPP1k=; b=i+4JoQ8M/gAjmEM1/ZnMU+gPFwcBTB41HwxK2sFZIhki+DnJSmVaJw6SvP3BRoTl/yzU5l cb/cv2ks134I5NEYeNdSCo3AeMHvczJSi9ThjPzlO/sJ2DnYVnmXg/vegN0/XWETVmG/BO ybRg/kxmKeBfPOTR0p03ca6PM62o7Lk/HqhJPgMMavCjTcDdZhuEGzDFh+V02vKXfwUsrj tCBPLY+WQC2pluxWO8y9EOk/hsbaCIz/1Zdoa/MMQU3VAIbiPuDkOVCUBFjsRos8m8qIGB YgkxMJj0J6Lw2ufRDFrNrQQUCKuxmgwNoIXoon/L7bIUbiMM238kQ+vacKFK6g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707764026; a=rsa-sha256; cv=none; b=d1zHUpdM9HW0LDceEyR9IA0MOBQ2Ry7cGivhWDwePzUD+RKOWxc1V4/SAIMMfuOdKI94Tt MzxW/ITUS3Iftj6Vxw/dkivHhTEgy0a+UvMggPf9dOzoAZa2q9LfOKdwxBjSJU82Di8ZjC qA/DTEiwVX832zoUS1QiybgT3YBgAH4kYjxZ26FS+aauO3StSbcSlMHaKPANZrudN7IZh4 QcGw52sO/JNp/zS65EDt1sOTEVwFsQ/L7W5Dw+HXJ4Dh0SCel3vi3uRhld4ovJyDqLWn+M +XdqYm2vcAoA9DaebqbuXILQACgmqA5gRJqd+NiEOjQJEWRLWekys1H2CPKVXA== 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=1707764026; 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=NlIj1shqCcq5V1/Llk2BCsFjf/+Fw7p6gFLe1OTPP1k=; b=BpeN6WfKgsjVJzs4yZlZX8A6UhdaNvRvxy37ORrnTAzdQfLXjsj96tG3QYuR0HQ5tt5URy mcVdQFSDfKM7a4ozt7swStGp44TXQ+uR7uHu6XS86w5WK89GHMbMU9A3PRB7RXIu0WUyTB jHZO25fZ6ALcZ/3C4OzZ9GQxRwDmKdTNsPl38yl8Due9TPbfZ2u9Otx1/Jp5PyQdHFEHEM mvExxGkaI1+cIK7Z+7x5ob+G9alD+8Hz+pJ8uHNZK1mXdd7USXj4yQwPI4qrjGgb8uAv39 Zxmio+9MvJ0IXZM7N2aZl0Zd6r9L4hMqVYKox6ZtMIJgmtHq9hkhrACetCSYTw== 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 4TYYWt3xhhzjnh; Mon, 12 Feb 2024 18:53:46 +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 41CIrks4030815; Mon, 12 Feb 2024 18:53:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41CIrkbw030812; Mon, 12 Feb 2024 18:53:46 GMT (envelope-from git) Date: Mon, 12 Feb 2024 18:53:46 GMT Message-Id: <202402121853.41CIrkbw030812@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: 994cc8392123 - main - reboot: Allow this to be installed as nextboot 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: 994cc839212393cd2e591a6a9908ee9a94fdb18f Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=994cc839212393cd2e591a6a9908ee9a94fdb18f commit 994cc839212393cd2e591a6a9908ee9a94fdb18f Author: Warner Losh AuthorDate: 2024-02-12 18:46:11 +0000 Commit: Warner Losh CommitDate: 2024-02-12 18:46:11 +0000 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 --- sbin/reboot/reboot.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c index 21acf7514388..a31c31892745 100644 --- a/sbin/reboot/reboot.c +++ b/sbin/reboot/reboot.c @@ -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)