public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH,RFC,resend] printk: restore previous console_loglevel when re-enabling logging
@ 2009-07-06 11:31 Frans Pop
  2009-07-10 14:07 ` Ingo Molnar
  2009-07-10 14:21 ` [tip:core/printk] printk: Restore " tip-bot for Frans Pop
  0 siblings, 2 replies; 3+ messages in thread
From: Frans Pop @ 2009-07-06 11:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: cryptsetup, Ingo Molnar, Andrew Morton

When logging to console is disabled from userspace using klogctl()
and later re-enabled, console_loglevel gets set to the default
log level instead to the previous value.
This means that if the kernel was booted with 'quiet', the boot is
suddenly no longer quiet after logging to console gets re-enabled.

Save the current console_loglevel when logging is disabled and
restore to that value. If the log level is set to a specific value
while disabled, this is interpreted as an implicit re-enabling of
the logging.

Signed-off-by: Frans Pop <elendil@planet.nl>
---

Resend. The problem that prompted this patch is described in
http://lkml.org/lkml/2009/6/28/234

There are two variations possible on the patch below.

1) If klogctl(7) is called while logging is not disabled, then set level
   to default (partially preserving current functionality):
 	case 7:		/* Enable logging to console */
-		console_loglevel = default_console_loglevel;
+		if (saved_console_loglevel == -1)
+			console_loglevel = default_console_loglevel;
+		else {
+			console_loglevel = saved_console_loglevel;
+			saved_console_loglevel = -1;
+		}

2) If klogctl(8) is called while logging is disabled, then don't enable
   logging, but remember the requested value for when logging does get
   enabled again:
 	case 8:		/* Set level of messages printed to console */
[...]
- 		console_loglevel = len;
+		if (saved_console_loglevel == -1)
+	 		console_loglevel = len;
+		else
+			saved_console_loglevel = len;

Yet another option would be to ignore the request.


diff --git a/kernel/printk.c b/kernel/printk.c
index b4d97b5..acbf050 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -271,6 +271,7 @@ int do_syslog(int type, char __user *buf, int len)
 	int do_clear = 0;
 	char c;
 	int error = 0;
+	static int saved_console_loglevel = -1;
 
 	error = security_syslog(type);
 	if (error)
@@ -372,10 +373,15 @@ int do_syslog(int type, char __user *buf, int len)
 		logged_chars = 0;
 		break;
 	case 6:		/* Disable logging to console */
+		if (saved_console_loglevel == -1)
+			saved_console_loglevel = console_loglevel;
 		console_loglevel = minimum_console_loglevel;
 		break;
 	case 7:		/* Enable logging to console */
-		console_loglevel = default_console_loglevel;
+		if (saved_console_loglevel != -1) {
+			console_loglevel = saved_console_loglevel;
+			saved_console_loglevel = -1;
+		}
 		break;
 	case 8:		/* Set level of messages printed to console */
 		error = -EINVAL;
@@ -384,6 +390,8 @@ int do_syslog(int type, char __user *buf, int len)
 		if (len < minimum_console_loglevel)
 			len = minimum_console_loglevel;
 		console_loglevel = len;
+		/* Implicitly re-enable logging to console */
+		saved_console_loglevel = -1;
 		error = 0;
 		break;
 	case 9:		/* Number of chars in the log buffer */

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH,RFC,resend] printk: restore previous console_loglevel when re-enabling logging
  2009-07-06 11:31 [PATCH,RFC,resend] printk: restore previous console_loglevel when re-enabling logging Frans Pop
@ 2009-07-10 14:07 ` Ingo Molnar
  2009-07-10 14:21 ` [tip:core/printk] printk: Restore " tip-bot for Frans Pop
  1 sibling, 0 replies; 3+ messages in thread
From: Ingo Molnar @ 2009-07-10 14:07 UTC (permalink / raw)
  To: Frans Pop, Linus Torvalds, Robin Getz
  Cc: linux-kernel, cryptsetup, Andrew Morton


* Frans Pop <elendil@planet.nl> wrote:

> When logging to console is disabled from userspace using klogctl()
> and later re-enabled, console_loglevel gets set to the default
> log level instead to the previous value.
> This means that if the kernel was booted with 'quiet', the boot is
> suddenly no longer quiet after logging to console gets re-enabled.
> 
> Save the current console_loglevel when logging is disabled and
> restore to that value. If the log level is set to a specific value
> while disabled, this is interpreted as an implicit re-enabling of
> the logging.
> 
> Signed-off-by: Frans Pop <elendil@planet.nl>
> ---
> 
> Resend. The problem that prompted this patch is described in
> http://lkml.org/lkml/2009/6/28/234
> 
> There are two variations possible on the patch below.
> 
> 1) If klogctl(7) is called while logging is not disabled, then set level
>    to default (partially preserving current functionality):
>  	case 7:		/* Enable logging to console */
> -		console_loglevel = default_console_loglevel;
> +		if (saved_console_loglevel == -1)
> +			console_loglevel = default_console_loglevel;
> +		else {
> +			console_loglevel = saved_console_loglevel;
> +			saved_console_loglevel = -1;
> +		}
> 
> 2) If klogctl(8) is called while logging is disabled, then don't enable
>    logging, but remember the requested value for when logging does get
>    enabled again:
>  	case 8:		/* Set level of messages printed to console */
> [...]
> - 		console_loglevel = len;
> +		if (saved_console_loglevel == -1)
> +	 		console_loglevel = len;
> +		else
> +			saved_console_loglevel = len;
> 
> Yet another option would be to ignore the request.

Looks like a possible solution to a real problem (most distros today 
boot with quiet) - albeit it does change previous behavior so 
objections are possible on those grounds.

I've queued it up in the tip:core/printk tree and will push it out 
to linux-next in a few days if there are no objections.

Small sidenote: i moved the (somewhat obscurely placed) 
saved_console_loglevel static variable out of local variable scope 
and next to the console loglevel definitions (such as 
console_printk[]), to increase its visibility as globally relevant 
state and to move it next to the state this variable affects.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:core/printk] printk: Restore previous console_loglevel when re-enabling logging
  2009-07-06 11:31 [PATCH,RFC,resend] printk: restore previous console_loglevel when re-enabling logging Frans Pop
  2009-07-10 14:07 ` Ingo Molnar
@ 2009-07-10 14:21 ` tip-bot for Frans Pop
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Frans Pop @ 2009-07-10 14:21 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, torvalds, akpm, elendil, tglx, mingo

Commit-ID:  1aaad49e856ce41adc07d8ae0c8ef35fc4483245
Gitweb:     http://git.kernel.org/tip/1aaad49e856ce41adc07d8ae0c8ef35fc4483245
Author:     Frans Pop <elendil@planet.nl>
AuthorDate: Mon, 6 Jul 2009 13:31:48 +0200
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Fri, 10 Jul 2009 16:02:23 +0200

printk: Restore previous console_loglevel when re-enabling logging

When logging to console is disabled from userspace using klogctl()
and later re-enabled, console_loglevel gets set to the default
log level instead to the previous value.

This means that if the kernel was booted with 'quiet', the boot is
suddenly no longer quiet after logging to console gets re-enabled.

Save the current console_loglevel when logging is disabled and
restore to that value. If the log level is set to a specific value
while disabled, this is interpreted as an implicit re-enabling of
the logging.

The problem that prompted this patch is described in:

    http://lkml.org/lkml/2009/6/28/234

There are two variations possible on the patch below:

 1) If klogctl(7) is called while logging is not disabled, then set level
    to default (partially preserving current functionality):
  	case 7:		/* Enable logging to console */
 -		console_loglevel = default_console_loglevel;
 +		if (saved_console_loglevel == -1)
 +			console_loglevel = default_console_loglevel;
 +		else {
 +			console_loglevel = saved_console_loglevel;
 +			saved_console_loglevel = -1;
 +		}

 2) If klogctl(8) is called while logging is disabled, then don't enable
    logging, but remember the requested value for when logging does get
    enabled again:
  	case 8:		/* Set level of messages printed to console */
 [...]
 - 		console_loglevel = len;
 +		if (saved_console_loglevel == -1)
 +			console_loglevel = len;
 +		else
 +			saved_console_loglevel = len;

Yet another option would be to ignore the request.

Signed-off-by: Frans Pop <elendil@planet.nl>
Cc: cryptsetup@packages.debian.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
LKML-Reference: <200907061331.49930.elendil@planet.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>


---
 kernel/printk.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/kernel/printk.c b/kernel/printk.c
index 668df35..e0daaf5 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -67,6 +67,8 @@ int console_printk[4] = {
 	DEFAULT_CONSOLE_LOGLEVEL,	/* default_console_loglevel */
 };
 
+static int saved_console_loglevel = -1;
+
 /*
  * Low level drivers may need that to know if they can schedule in
  * their unblank() callback or not. So let's export it.
@@ -378,10 +380,15 @@ int do_syslog(int type, char __user *buf, int len)
 		logged_chars = 0;
 		break;
 	case 6:		/* Disable logging to console */
+		if (saved_console_loglevel == -1)
+			saved_console_loglevel = console_loglevel;
 		console_loglevel = minimum_console_loglevel;
 		break;
 	case 7:		/* Enable logging to console */
-		console_loglevel = default_console_loglevel;
+		if (saved_console_loglevel != -1) {
+			console_loglevel = saved_console_loglevel;
+			saved_console_loglevel = -1;
+		}
 		break;
 	case 8:		/* Set level of messages printed to console */
 		error = -EINVAL;
@@ -390,6 +397,8 @@ int do_syslog(int type, char __user *buf, int len)
 		if (len < minimum_console_loglevel)
 			len = minimum_console_loglevel;
 		console_loglevel = len;
+		/* Implicitly re-enable logging to console */
+		saved_console_loglevel = -1;
 		error = 0;
 		break;
 	case 9:		/* Number of chars in the log buffer */

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-07-10 14:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-06 11:31 [PATCH,RFC,resend] printk: restore previous console_loglevel when re-enabling logging Frans Pop
2009-07-10 14:07 ` Ingo Molnar
2009-07-10 14:21 ` [tip:core/printk] printk: Restore " tip-bot for Frans Pop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox