From nobody Mon May 5 16:05:25 2025 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 4ZrmZs69C6z5vhS1; Mon, 05 May 2025 16:05:25 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZrmZs5g9nz3Jpn; Mon, 05 May 2025 16:05:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746461125; 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=LttUG2sPGnI69RG8sy9+J3p8DGoYrCqpJB/X+rTOUy4=; b=NmBNxaIrNujBIxJRIHyE0H7qTZCq4YA2mzUTvlfhBl9OOBKGb9iY9Fe5TnbArAAhe11gem xg0uxsWGogdYZxzR+KX8fLLGFsKzDd4QD6QbzrMQzRCI77LABGLqTwSc/RANHN00SR116T 78jzFmDgE/25tcaSpp5A2ReNdupS6e27kurjh6lWXURW+woM0agHMObrCxGDqL8QSSiMxc iHrSyQotWVkq7BZqH9XWvad1vZflFnRONsgJESfq7R6ytsr6qCGw/vHDP6ClvgZnOXR0W3 fN/RgwFefZwxl/IF8Cxz4FOBYLf04D1SXDVDmwPcSyEP0tbNmkKvITkWjGKV/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746461125; 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=LttUG2sPGnI69RG8sy9+J3p8DGoYrCqpJB/X+rTOUy4=; b=uzgoZLsbCTyeC4P2sRGi7uLFdpxEKVBA7fU7CQ/m9slSeuUMxxDwJDq/npyhdrEWBZwyx2 RJDHEuE5/J8XbktH5gemEzKpAZU1reH7cFmbAaIuZyVxXBuLZ6OJR2Am1u4zmAsaDE5rHA bioP7Bo4UiuSVXd00JjaURF/u1Wkcm0G+wR4OFktd16GB1vcpms9aOk23IpTtW2aQ6srx5 FZmD3Ad7zZAW9JzGz/BMcZ/72dO5x9kPj1kNRV1WEFAQO2E7wnxPClgTWNiu8p5RtJaSHR s1oMYuVzCzfAWQNbLxgGQig0OPAZL5EM9iKqFO+hNL2cSDD6H6BGRVhr7DNZQQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746461125; a=rsa-sha256; cv=none; b=t4SSdyKfM8GgmCUCqbpzo23oqWmczo4SOyAV6T9FCNcRD+VD8vAduZ9SeOLSuQeIXq74EP 4YC19utBjTn++bfebITH1AjOINrCuR3UQRhP4q2i2WCHpnPNpwQdoyNCe4H7ejJQNkktpR xwm31Ju0nQb3uwhDWVjmA2UbtotLK+Uz+0OdRMUv4qpXhaxbdKLSWrHZoubcKATJbrhLlK vCpRCVNNfsba32dExcSjOtYaEP7tHHxvMOkxdyHlFteFFbkSv8ULzEDlTsBq/M5wDFJAdK D7NYJAHfs8XQ952usYxf3TF9CnZ/vUWK9TIix3CpMFEUYkNr3AzMx8tvg+GKiw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4ZrmZs5D6Xz5Y5; Mon, 05 May 2025 16:05:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 545G5P4g053123; Mon, 5 May 2025 16:05:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 545G5PHt053120; Mon, 5 May 2025 16:05:25 GMT (envelope-from git) Date: Mon, 5 May 2025 16:05:25 GMT Message-Id: <202505051605.545G5PHt053120@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 7fb88c20eccc - main - shutdown(8): refuse to run if /var/run/noshutdown is present 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7fb88c20eccc3fd2118fda2ba58d7afe2b87f7e3 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=7fb88c20eccc3fd2118fda2ba58d7afe2b87f7e3 commit 7fb88c20eccc3fd2118fda2ba58d7afe2b87f7e3 Author: Konstantin Belousov AuthorDate: 2025-05-04 13:39:32 +0000 Commit: Konstantin Belousov CommitDate: 2025-05-05 16:04:22 +0000 shutdown(8): refuse to run if /var/run/noshutdown is present Reviewed by: bapt, kevans, olce Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D50166 --- sbin/shutdown/shutdown.8 | 23 +++++++++++++++++++++-- sbin/shutdown/shutdown.c | 18 +++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/sbin/shutdown/shutdown.8 b/sbin/shutdown/shutdown.8 index ab90af6244e9..ed44ac36aef6 100644 --- a/sbin/shutdown/shutdown.8 +++ b/sbin/shutdown/shutdown.8 @@ -36,7 +36,7 @@ .Nm .Op Fl .Oo -.Fl c | Fl h | Fl p | +.Fl c | Fl f | Fl h | Fl p | .Fl r | Fl k .Oc .Oo @@ -71,6 +71,12 @@ At the present time, only systems with BMC supported by the driver that implement this functionality support this flag. The amount of time the system is off is dependent on the device that implements this feature. +.It Fl f +The +.Nm +command ignores the presence of the +.Pa /var/run/noshutdown +file. .It Fl h The system is halted at the specified .Ar time . @@ -206,6 +212,12 @@ file that .Nm created will be removed automatically. .Pp +If the +.Pa /var/run/noshutdown +file is present, +.Nm +exits without executing any action on the system. +.Pp When run without options, the .Nm utility will place the system into single user mode at the @@ -219,11 +231,18 @@ is equivalent to running: shutdown -p now .Ed .Sh FILES -.Bl -tag -width /var/run/nologin -compact +.Bl -tag -width /var/run/noshutdown -compact .It Pa /var/run/nologin tells .Xr login 1 not to let anyone log in +.It Pa /var/run/noshutdown +prevents +.Nm +from initiating an action on the system. +Can be overridden with the +.Fl f +option. .El .Sh EXAMPLES Reboot the system in 30 minutes and display a warning message on the terminals diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c index e92d41220a20..762b23ab6bd9 100644 --- a/sbin/shutdown/shutdown.c +++ b/sbin/shutdown/shutdown.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -79,7 +80,8 @@ static struct interval { #undef S static time_t offset, shuttime; -static int docycle, dohalt, dopower, doreboot, killflg, mbuflen, oflag; +static int docycle, dohalt, dopower, doreboot, ign_noshutdown, + killflg, mbuflen, oflag; static char mbuf[BUFSIZ]; static const char *nosync, *whom; @@ -100,6 +102,7 @@ main(int argc, char **argv) { char *p, *endp; struct passwd *pw; + struct stat st; int arglen, ch, len, readstdin; bool dowarn; @@ -133,7 +136,7 @@ main(int argc, char **argv) goto poweroff; } - while ((ch = getopt(argc, argv, "-chknopqr")) != -1) + while ((ch = getopt(argc, argv, "-cfhknopqr")) != -1) switch (ch) { case '-': readstdin = 1; @@ -141,6 +144,9 @@ main(int argc, char **argv) case 'c': docycle = 1; break; + case 'f': + ign_noshutdown = 1; + break; case 'h': dohalt = 1; break; @@ -216,6 +222,12 @@ poweroff: } mbuflen = strlen(mbuf); + if (!ign_noshutdown && stat(_PATH_NOSHUTDOWN, &st) == 0) { + (void)printf("Shutdown cannot be done, " _PATH_NOSHUTDOWN + " is present\n"); + exit(2); + } + if (offset) { BOOTTRACE("Shutdown at %s", ctime(&shuttime)); (void)printf("Shutdown at %.24s.\n", ctime(&shuttime)); @@ -593,7 +605,7 @@ usage(const char *cp) if (cp != NULL) warnx("%s", cp); (void)fprintf(stderr, - "usage: shutdown [-] [-c | -h | -p | -r | -k] [-o [-n]] [-q] time [warning-message ...]\n" + "usage: shutdown [-] [-c | -f | -h | -p | -r | -k] [-o [-n]] [-q] time [warning-message ...]\n" " poweroff\n"); exit(1); }