Date: Mon, 5 May 2025 16:05:25 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 7fb88c20eccc - main - shutdown(8): refuse to run if /var/run/noshutdown is present Message-ID: <202505051605.545G5PHt053120@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=7fb88c20eccc3fd2118fda2ba58d7afe2b87f7e3 commit 7fb88c20eccc3fd2118fda2ba58d7afe2b87f7e3 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2025-05-04 13:39:32 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> 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 <sys/param.h> #include <sys/boottrace.h> #include <sys/resource.h> +#include <sys/stat.h> #include <sys/syslog.h> #include <sys/time.h> @@ -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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505051605.545G5PHt053120>