Module Name: src Committed By: pgoyette Date: Tue May 31 05:44:19 UTC 2016
Modified Files: src/share/man/man7: sysctl.7 src/sys/kern: init_sysctl.c Log Message: Add a new kern.messages sysctl to allow kernel message verbosity to be altered after boot. Fixes PR kern/46539 using patch submitted by Nat Sloss. To generate a diff of this commit: cvs rdiff -u -r1.101 -r1.102 src/share/man/man7/sysctl.7 cvs rdiff -u -r1.210 -r1.211 src/sys/kern/init_sysctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man7/sysctl.7 diff -u src/share/man/man7/sysctl.7:1.101 src/share/man/man7/sysctl.7:1.102 --- src/share/man/man7/sysctl.7:1.101 Wed May 25 20:47:57 2016 +++ src/share/man/man7/sysctl.7 Tue May 31 05:44:19 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: sysctl.7,v 1.101 2016/05/25 20:47:57 wiz Exp $ +.\" $NetBSD: sysctl.7,v 1.102 2016/05/31 05:44:19 pgoyette Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95 .\" -.Dd May 25, 2016 +.Dd May 31, 2016 .Dt SYSCTL 7 .Os .Sh NAME @@ -315,6 +315,7 @@ privilege may change the value. .It kern.maxproc integer yes .It kern.maxptys integer yes .It kern.maxvnodes integer yes +.It kern.messages integer yes .It kern.mbuf node not applicable .It kern.memlock integer no .It kern.memlock_range integer no @@ -739,6 +740,18 @@ Returns 1 if the .St -p1003.1b-93 Memory Protection Option is available on this system, otherwise\ 0. +.It Li kern.messages +Kernel console message verbosity. +See +.Sy \<sys/reboot.h\> +.Bl -column "verbosity" "setting" -offset indent +.It Sy Verbosity Setting +.It \ \ \ \ 0 Silent Sy AB_SILENT +.It \ \ \ \ 1 Quiet Sy AB_QUIET +.It \ \ \ \ 2 Normal Sy AB_NORMAL +.It \ \ \ \ 3 Verbose Sy AB_VERBOSE +.It \ \ \ \ 4 Debug Sy AB_DEBUG +.El .It Li kern.module Settings related to kernel modules. The third level names for the settings are described below. Index: src/sys/kern/init_sysctl.c diff -u src/sys/kern/init_sysctl.c:1.210 src/sys/kern/init_sysctl.c:1.211 --- src/sys/kern/init_sysctl.c:1.210 Mon Nov 9 01:21:18 2015 +++ src/sys/kern/init_sysctl.c Tue May 31 05:44:19 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: init_sysctl.c,v 1.210 2015/11/09 01:21:18 pgoyette Exp $ */ +/* $NetBSD: init_sysctl.c,v 1.211 2016/05/31 05:44:19 pgoyette Exp $ */ /*- * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.210 2015/11/09 01:21:18 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.211 2016/05/31 05:44:19 pgoyette Exp $"); #include "opt_sysv.h" #include "opt_compat_netbsd.h" @@ -56,6 +56,7 @@ __KERNEL_RCSID(0, "$NetBSD: init_sysctl. #include <sys/filedesc.h> #include <sys/tty.h> #include <sys/kmem.h> +#include <sys/reboot.h> #include <sys/resource.h> #include <sys/resourcevar.h> #include <sys/exec.h> @@ -110,6 +111,7 @@ dcopyout(struct lwp *l, const void *kadd static int sysctl_kern_trigger_panic(SYSCTLFN_PROTO); #endif static int sysctl_kern_maxvnodes(SYSCTLFN_PROTO); +static int sysctl_kern_messages(SYSCTLFN_PROTO); static int sysctl_kern_rtc_offset(SYSCTLFN_PROTO); static int sysctl_kern_maxproc(SYSCTLFN_PROTO); static int sysctl_kern_hostid(SYSCTLFN_PROTO); @@ -590,6 +592,12 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl SYSCTL_DESCR("Information from build environment"), NULL, 0, __UNCONST(buildinfo), 0, CTL_KERN, CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "messages", + SYSCTL_DESCR("Kernel message verbosity"), + sysctl_kern_messages, 0, NULL, 0, + CTL_KERN, CTL_CREATE, CTL_EOL); } SYSCTL_SETUP(sysctl_hw_misc_setup, "sysctl hw subtree misc setup") @@ -760,6 +768,72 @@ sysctl_kern_maxvnodes(SYSCTLFN_ARGS) } /* + * sysctl helper routine for kern.messages. + * Alters boothowto to display kernel messages in increasing verbosity + * from 0 to 4. + */ + +#define MAXMESSAGES 4 +static int +sysctl_kern_messages(SYSCTLFN_ARGS) +{ + int error, messageverbose, messagemask, newboothowto; + struct sysctlnode node; + + messagemask = (AB_NORMAL|AB_QUIET|AB_SILENT|AB_VERBOSE|AB_DEBUG); + switch (boothowto & messagemask) { + case AB_SILENT: + messageverbose = 0; + break; + case AB_QUIET: + messageverbose = 1; + break; + case AB_VERBOSE: + messageverbose = 3; + break; + case AB_DEBUG: + messageverbose = 4; + break; + case AB_NORMAL: + default: + messageverbose = 2; +} + + node = *rnode; + node.sysctl_data = &messageverbose; + error = sysctl_lookup(SYSCTLFN_CALL(&node)); + if (error || newp == NULL) + return (error); + if (messageverbose < 0 || messageverbose > MAXMESSAGES) + return EINVAL; + + /* Set boothowto */ + newboothowto = boothowto & ~messagemask; + + switch (messageverbose) { + case 0: + newboothowto |= AB_SILENT; + break; + case 1: + newboothowto |= AB_QUIET; + break; + case 3: + newboothowto |= AB_VERBOSE; + break; + case 4: + newboothowto |= AB_DEBUG; + break; + case 2: + default: /* Messages default to normal. */ + break; + } + + boothowto = newboothowto; + + return (0); +} + +/* * sysctl helper routine for rtc_offset - set time after changes */ static int