* [PATCH] dmesg: fix console-level off-by-one
@ 2012-10-01 23:54 Bjørn Mork
2012-10-02 9:46 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Bjørn Mork @ 2012-10-01 23:54 UTC (permalink / raw)
To: util-linux; +Cc: Bjørn Mork
commit f06ec64f dmesg; support level names (e.g. --console-level=alert)
introduced an off-by-one error. The kernel will print messages with
a *higher* level than the console-level. The bug made it impossible to
set the level for debugging, like it is documented in e.g
Documentation/networking/netconsole.txt :
nemi:/tmp# dmesg -n 8
dmesg: unknown level '8'
And attempting to set the "emerg" level would result in an invalid 0 value:
nemi:/tmp# dmesg -n emerg
dmesg: klogctl failed: Invalid argument
Restoring the old behaviour for numeric levels, and mapping the level
names so that "dmesg -n debug" behaves as expected: logging everything
at level "debug" and higher.
Signed-off-by: Bjørn Mork <bjorn@mork.no>
---
sys-utils/dmesg.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 0ee03ee..fe39256 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -232,19 +232,23 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
*/
static int parse_level(const char *str, size_t len)
{
+ int offset = 0;
+
if (!str)
return -1;
- if (!len)
+ if (!len) {
len = strlen(str);
+ offset = 1;
+ }
errno = 0;
if (isdigit(*str)) {
char *end = NULL;
- long x = strtol(str, &end, 10);
+ long x = strtol(str, &end, 10) - offset;
if (!errno && end && end > str && (size_t) (end - str) == len &&
x >= 0 && (size_t) x < ARRAY_SIZE(level_names))
- return x;
+ return x + offset;
} else {
size_t i;
@@ -252,7 +256,7 @@ static int parse_level(const char *str, size_t len)
const char *n = level_names[i].name;
if (strncasecmp(str, n, len) == 0 && *(n + len) == '\0')
- return i;
+ return i + offset;
}
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] dmesg: fix console-level off-by-one
2012-10-01 23:54 [PATCH] dmesg: fix console-level off-by-one Bjørn Mork
@ 2012-10-02 9:46 ` Karel Zak
0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2012-10-02 9:46 UTC (permalink / raw)
To: Bjørn Mork; +Cc: util-linux
On Tue, Oct 02, 2012 at 01:54:49AM +0200, Bjørn Mork wrote:
> sys-utils/dmesg.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
Ah... applied, thanks!
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-02 9:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-01 23:54 [PATCH] dmesg: fix console-level off-by-one Bjørn Mork
2012-10-02 9:46 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).