From nobody Fri Aug 09 16:01:19 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 4WgTDH2r2Jz5SK4j; Fri, 09 Aug 2024 16:01:19 +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 4WgTDH1H16z4rDx; Fri, 9 Aug 2024 16:01:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723219279; 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=fCtlCionTaC4ku8WMgiVi5kRdikCeHGX/WndO5bVFDg=; b=oLRGGVqpUT9/9x1TKRdLskrPaI7kkrO5+xwYbDb1SJ6u6h3IXz67K21G7z6kD//ZVK8+Bp n4LMSwm8xNHlwfUP2nlUSHA/Dzshl530suTtFdOK7tE243IXc5NVyFhySjYlNPk1Ls9GEd cFFx8M3KK/sY27LSHORYVeu1hLJGqiGci8Qb5uf2aIDsmnKax0bYaONdyJpMaIsyP80Vij q1ybm11+fRTJFuppaFELkpL16egPocmrxkYQEL1XDrmfkPLq20o1NHeyYtk1w6CbRBmPIu cfmhWIsHnik5gaw+yqSxI7bhahLhlLE4m/OE7e8zd3iNNb8ERjZzGPwb+hWbFg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1723219279; a=rsa-sha256; cv=none; b=gN589zHjnbQy6fwbcHGJN1/4xH/Rswk7apTj6w7jDicbpWJkQDYGltf7xvHVwl7YlmI/eg tm1TLf/BW4A95cmbNcsSiL4eT3YUM+JSePigjQzNcY+fGJZvlLJpbe7Jwv4PVpGZ2acgwm uwTW5cDETgD0V/idROr0QsjJh0c0wsIQHTDxIi7VJ//DpGz88G5WKGGKdcVOT+6Mf3g7z0 hh2KZyaQ0oKmKAJ6PqCZYFA9u2wkP3tEeAQ5QL27r6ahtcJxWaS3XRwjw/cYVGgiGfBEYh o00TYspb/Ex0zaMePEwQK+tovEzlVw8t0vA2tqk4+KcTF4yScO249qScaWvhnA== 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=1723219279; 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=fCtlCionTaC4ku8WMgiVi5kRdikCeHGX/WndO5bVFDg=; b=OGTwKVdOOJpjQg8ad+ay3QBpNsw2BhKegy/YZ3TIVY3HkVvmBdLFkjVVE+gDv/JrdPRZxj T342dRThib+j3urG2fw14muxNVltUcqRAwUO9NPfiUVT2EVSGkDXuiDUmy9XafLEpXCrjN vhyQ7ZD6g3alEBmk+4aVR/nKbUBbau7lw1YhVWRKgwt6GSwiHCUCOG8IWn1GY0uULMarlf 46j6QDavRWIKN/I1MUMp07NGYf7b/7NxCUXUG8N1TZPJof6wST6PnFkI+5uw0mh8ZrGWrv OjSKfB5NTfADIn+4gFvlZny4cvQ8q0Cr/mueybhWqBhXqZ44vo9P/sIZgbLQ1A== 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 4WgTDH0tmszNYn; Fri, 9 Aug 2024 16:01:19 +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 479G1Jvt043281; Fri, 9 Aug 2024 16:01:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 479G1JF3043278; Fri, 9 Aug 2024 16:01:19 GMT (envelope-from git) Date: Fri, 9 Aug 2024 16:01:19 GMT Message-Id: <202408091601.479G1JF3043278@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 6c7ec630c24f - main - shutdown: add a -q(uiet) flag to suppress warning messages 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6c7ec630c24fded12e237b5ffda115cc268b75c2 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=6c7ec630c24fded12e237b5ffda115cc268b75c2 commit 6c7ec630c24fded12e237b5ffda115cc268b75c2 Author: Kyle Evans AuthorDate: 2024-08-09 16:01:11 +0000 Commit: Kyle Evans CommitDate: 2024-08-09 16:01:11 +0000 shutdown: add a -q(uiet) flag to suppress warning messages The system-wide warning makes sense in multi-user environments, but shutdown(8) may be used on systems or in scenarios where there's nobody to warn and wall(1) just introduces unnecessary complexity and overhead to the shutdown process. Add an option to suppress the warning entirely for those contexts that want to do so, which are anticipated to mainly be in appliance or single-user desktop-style systems. Reviewed by: des Reviewed by: allanjude, imp (earlier version) Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D46216 --- sbin/shutdown/shutdown.8 | 9 ++++++++- sbin/shutdown/shutdown.c | 23 ++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/sbin/shutdown/shutdown.8 b/sbin/shutdown/shutdown.8 index 70df537b8bf5..ab90af6244e9 100644 --- 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 4, 2024 .Dt SHUTDOWN 8 .Os .Sh NAME @@ -43,6 +43,7 @@ .Fl o .Op Fl n .Oc +.Op Fl q .Ar time .Op Ar warning-message ... .Nm poweroff @@ -113,6 +114,12 @@ to or .Xr reboot 8 . This option should probably not be used. +.It Fl q +Shut down quietly. +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 index 80a9e14fc8d3..101e003b44e2 100644 --- 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 badtime(void); 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 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) goto poweroff; } - while ((ch = getopt(argc, argv, "-chknopr")) != -1) + while ((ch = getopt(argc, argv, "-chknoprq")) != -1) switch (ch) { case '-': readstdin = 1; @@ -156,6 +159,9 @@ main(int argc, char **argv) case 'r': doreboot = 1; break; + case 'q': + dowarn = false; + break; case '?': default: usage((char *)NULL); @@ -178,6 +184,8 @@ main(int argc, char **argv) getoffset(*argv++); poweroff: + if (!dowarn && *argv != NULL) + usage("warning-message supplied but suppressed with -q"); if (*argv) { for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) { arglen = strlen(*argv); @@ -235,12 +243,12 @@ poweroff: 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 @@ loop(void) * 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 @@ 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 | -h | -p | -r | -k] [-o [-n]] [-q] time [warning-message ...]\n" " poweroff\n"); exit(1); }