diff --git a/sbin/shutdown/shutdown.8 b/sbin/shutdown/shutdown.8 --- a/sbin/shutdown/shutdown.8 +++ b/sbin/shutdown/shutdown.8 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd November 7, 2022 +.Dd August 22, 2024 .Dt SHUTDOWN 8 .Os .Sh NAME @@ -43,6 +43,7 @@ .Fl o .Op Fl n .Oc +.Op Fl W .Ar time .Op Ar warning-message ... .Nm poweroff @@ -113,6 +114,11 @@ or .Xr reboot 8 . This option should probably not be used. +.It Fl W +Suppress the warning message to all logged in users about system shutdown. +It is an error to supply a +.Ar warning-message +when warnings are suppressed. .It Ar time .Ar Time is the time at which diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c --- a/sbin/shutdown/shutdown.c +++ b/sbin/shutdown/shutdown.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -86,7 +87,7 @@ static void die_you_gravy_sucking_pig_dog(void); static void finish(int); static void getoffset(char *); -static void loop(void); +static void loop(bool); static void nolog(void); static void timeout(int); static void timewarn(int); @@ -100,12 +101,14 @@ char *p, *endp; struct passwd *pw; int arglen, ch, len, readstdin; + bool dowarn; #ifndef DEBUG if (geteuid()) errx(1, "NOT super-user"); #endif + dowarn = true; nosync = NULL; readstdin = 0; @@ -130,7 +133,7 @@ goto poweroff; } - while ((ch = getopt(argc, argv, "-chknopr")) != -1) + while ((ch = getopt(argc, argv, "-chknoprW")) != -1) switch (ch) { case '-': readstdin = 1; @@ -156,6 +159,9 @@ case 'r': doreboot = 1; break; + case 'W': + dowarn = false; + break; case '?': default: usage((char *)NULL); @@ -178,6 +184,8 @@ getoffset(*argv++); poweroff: + if (!dowarn && *argv != NULL) + usage("warning-message supplied but suppressed with -W"); if (*argv) { for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) { arglen = strlen(*argv); @@ -235,12 +243,12 @@ setsid(); #endif openlog("shutdown", LOG_CONS, LOG_AUTH); - loop(); + loop(dowarn); return(0); } static void -loop(void) +loop(bool dowarn) { struct interval *tp; u_int sltime; @@ -263,13 +271,14 @@ * the next wait time. */ if ((sltime = offset - tp->timeleft)) { - if (sltime > (u_int)(tp->timetowait / 5)) + if (dowarn && sltime > (u_int)(tp->timetowait / 5)) timewarn(offset); (void)sleep(sltime); } } for (;; ++tp) { - timewarn(tp->timeleft); + if (dowarn) + timewarn(tp->timeleft); if (!logged && tp->timeleft <= NOLOG_TIME) { logged = 1; nolog(); @@ -584,7 +593,7 @@ 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 | -h | -p | -r | -k] [-o [-n]] -W time [warning-message ...]\n" " poweroff\n"); exit(1); }