git: df79daa0fde8 - main - Reduce additional console output when muted

From: Warner Losh <imp_at_FreeBSD.org>
Date: Fri, 29 Nov 2024 21:39:28 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=df79daa0fde87ac90d4d73604b98107009c9c1bf

commit df79daa0fde87ac90d4d73604b98107009c9c1bf
Author:     Craig Woodward <Craig.Woodward@redcom.com>
AuthorDate: 2024-09-03 18:42:50 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-11-29 21:38:36 +0000

    Reduce additional console output when muted
    
    While trying to resolve some custom installer issues, we found that
    using conscontrol(8) or setting kern.always_console_output=0 in
    sysctrl.conf(5) did not always prevent console output. This is in part
    because some areas of the kernel were outputting to the console device
    without checking the status of the setting. These changes enforce
    checking of the value in both locations where console output occurs from
    kernel and init(8) based callouts.
    
    Details on changes:
    
     - Moves check for mute to earlier in sequence to silence kernel output
       even if EARLY_PRINTF is defined.
     - Modifies call prf_putbuf() and prf_putchar() in subr_prf.c to strip
       TOCONS flag if muting is enabled, to honor the setting at print
       level.
    
    This is a rather simple change, which increases areas where flags to
    silence console output are honored.  We have been running this change
    since 10/23 in-house without issue.  (Patching prior to 14.0 also
    required making cn_mute non-static.)
    
    Signed-off-by: Craig.Woodward@redcom.com
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/1407
---
 sys/kern/kern_cons.c |  5 +++--
 sys/kern/subr_prf.c  | 10 ++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/sys/kern/kern_cons.c b/sys/kern/kern_cons.c
index 2ab86d5905a9..fbe52735cf86 100644
--- a/sys/kern/kern_cons.c
+++ b/sys/kern/kern_cons.c
@@ -525,6 +525,9 @@ cnputc(int c)
 	struct consdev *cn;
 	const char *cp;
 
+	if (cn_mute || c == '\0')
+		return;
+
 #ifdef EARLY_PRINTF
 	if (early_putc != NULL) {
 		if (c == '\n')
@@ -534,8 +537,6 @@ cnputc(int c)
 	}
 #endif
 
-	if (cn_mute || c == '\0')
-		return;
 	STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) {
 		cn = cnd->cnd_cn;
 		if (!kdb_active || !(cn->cn_flags & CN_FLAG_NODEBUG)) {
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index 8ecabdec18d5..5cfc92e9761a 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -112,6 +112,7 @@ struct snprintf_arg {
 };
 
 extern	int log_open;
+extern	int cn_mute;
 
 static void  msglogchar(int c, int pri);
 static void  msglogstr(char *str, int pri, int filter_cr);
@@ -425,7 +426,7 @@ prf_putchar(int c, int flags, int pri)
 		msgbuftrigger = 1;
 	}
 
-	if (flags & TOCONS) {
+	if ((flags & TOCONS) && !cn_mute) {
 		if ((!KERNEL_PANICKED()) && (constty != NULL))
 			msgbuf_addchar(&consmsgbuf, c);
 
@@ -443,7 +444,7 @@ prf_putbuf(char *bufr, int flags, int pri)
 		msgbuftrigger = 1;
 	}
 
-	if (flags & TOCONS) {
+	if ((flags & TOCONS) && !cn_mute) {
 		if ((!KERNEL_PANICKED()) && (constty != NULL))
 			msgbuf_addstr(&consmsgbuf, -1,
 			    bufr, /*filter_cr*/ 0);
@@ -511,6 +512,11 @@ putchar(int c, void *arg)
 	if ((flags & TOTTY) && tp != NULL && !KERNEL_PANICKED())
 		tty_putchar(tp, c);
 
+	if ((flags & TOCONS ) && cn_mute) {
+		flags &= ~TOCONS;
+		ap->flags = flags;
+	}
+
 	if ((flags & (TOCONS | TOLOG)) && c != '\0')
 		putbuf(c, ap);
 }