From nobody Sat May 10 19:33:16 2025 X-Original-To: dev-commits-src-branches@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 4ZvwyP49mNz5vknD; Sat, 10 May 2025 19:33:17 +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 4ZvwyP0fcDz3TLk; Sat, 10 May 2025 19:33:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746905597; 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=9uxg2XzD/lHCzm0Ecj/wRGy+nxdNSn9ce09edfIwOiw=; b=BP2eSeS5keft7EgIlEYpiUoP86tEnimUgi4s9YfK84Doau5aQdnaLRtMVr6G2Zve1501D2 B1DqXGqkf5qVpBmc0E6VVA4oBoGsT+MzFqwdPyZ66ZwWeNO4Uz5Vnv15Pqr23mI6zhmJUl +EoJnPJFTv2v1FUq8dWljTYY9fmjJCuwXD0VpJStWc69Vv+hdE2Uyd5a6UVMHrGBXBnwXQ Xghuto8jtlfTaKM3rJbTFrQitibMPgQQEuEb5DjKQ9goAs0w6TpSOkv7cKF4ESc8LZ2peW kOSaMvkxzATYAvxt0+d2aBs8SwIsv6Ax9T35KzapzMOm6iDzYLLRk3Ciq1uVxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746905597; 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=9uxg2XzD/lHCzm0Ecj/wRGy+nxdNSn9ce09edfIwOiw=; b=yiHmnKdprny7IyAjp1wrrpwxMPEJkTQxwpoL2ra7w3Wzpt1Ir4P5X3FmWWi1ZM5eyJ/a0k mQAFDIZjdOwdkD7FRwlOUYKLS17Dg3qx8VtVTTzL4zzbvAd7ZvmLKhUiKqeX3RWWuV+Byn 5Hu0Yl7dG1wKhyu4APqwUn5K1RXFbFSe+bvxi5cazAnDmPPt1b2Ffdf9L9d/e/YPhN3I8Y ekge0Hc8XeADsZ8uaaSCRdekXGE90UlqJk1bk8n1y/1sAQUz3E/F5tEWzKrUB5E5RMl3al tYRgRrG35UVEJMMX/0Ot/U/N7YTLk3F7oVA53p+/sXQ3gIQ0XgBu9CNrczmfqQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746905597; a=rsa-sha256; cv=none; b=d0ywf4YMoLRElap1KStZwCpxOVIihGwZq5gCpALKRTMWXpP9e0xoorRg9elHF5hpe81ZWn W20y+uCzizH0ZKVQXGjPvSTaxJEO6o88AnjM0Fpq7MyXqFmJMl8azfXvn6y3n7Wcw7XqKp NnWuyBzmsvpli7IUNK8uJDgzfsBj9Five1++y7/IzRETNc4zk6jiTIEn4GMFUWF6kdw5LQ KALyDlkKfets0d6u3t5sSxURDw1GMyZCiiZ0tMPAHPFd0VE49HXke8rtEQU4UhZN18wZ8b PKJEbOu0tI+NZjR/6DLXQsgylzIvqfo3EmUf3Ojyi7ZuSNrReYL7FBXphp3FLg== 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 4ZvwyP02B1z1031; Sat, 10 May 2025 19:33:17 +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 54AJXGhg055199; Sat, 10 May 2025 19:33:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54AJXGcM055196; Sat, 10 May 2025 19:33:16 GMT (envelope-from git) Date: Sat, 10 May 2025 19:33:16 GMT Message-Id: <202505101933.54AJXGcM055196@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 16f17042683b - stable/14 - shutdown(8): refuse to run if /var/run/noshutdown is present List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 16f17042683bca6ae46d668bcc30e416f88cc42a Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=16f17042683bca6ae46d668bcc30e416f88cc42a commit 16f17042683bca6ae46d668bcc30e416f88cc42a Author: Konstantin Belousov AuthorDate: 2025-05-04 13:39:32 +0000 Commit: Konstantin Belousov CommitDate: 2025-05-10 18:57:46 +0000 shutdown(8): refuse to run if /var/run/noshutdown is present (cherry picked from commit 7fb88c20eccc3fd2118fda2ba58d7afe2b87f7e3) --- 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 7f60f22cc0e3..1b8b61df977e 100644 --- a/sbin/shutdown/shutdown.8 +++ b/sbin/shutdown/shutdown.8 @@ -38,7 +38,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 @@ -72,6 +72,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 . @@ -201,6 +207,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 @@ -214,11 +226,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 3864e44025eb..624f17cb366e 100644 --- a/sbin/shutdown/shutdown.c +++ b/sbin/shutdown/shutdown.c @@ -44,6 +44,7 @@ static char sccsid[] = "@(#)shutdown.c 8.4 (Berkeley) 4/28/95"; #include #include #include +#include #include #include @@ -90,7 +91,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; @@ -111,6 +113,7 @@ main(int argc, char **argv) { char *p, *endp; struct passwd *pw; + struct stat st; int arglen, ch, len, readstdin; #ifndef DEBUG @@ -142,7 +145,7 @@ main(int argc, char **argv) goto poweroff; } - while ((ch = getopt(argc, argv, "-chknopr")) != -1) + while ((ch = getopt(argc, argv, "-cfhknopr")) != -1) switch (ch) { case '-': readstdin = 1; @@ -150,6 +153,9 @@ main(int argc, char **argv) case 'c': docycle = 1; break; + case 'f': + ign_noshutdown = 1; + break; case 'h': dohalt = 1; break; @@ -220,6 +226,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)); @@ -596,7 +608,7 @@ usage(const char *cp) if (cp != NULL) warnx("%s", cp); (void)fprintf(stderr, - "usage: shutdown [-] [-c | -h | -p | -r | -k] [-o [-n]] time [warning-message ...]\n" + "usage: shutdown [-] [-c | -f | -h | -p | -r | -k] [-o [-n]] time [warning-message ...]\n" " poweroff\n"); exit(1); }