NetBSD Problem Report #54729
From tsutsui@ceres.dti.ne.jp Sun Dec 1 16:01:14 2019
Return-Path: <tsutsui@ceres.dti.ne.jp>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 926217A158
for <gnats-bugs@gnats.NetBSD.org>; Sun, 1 Dec 2019 16:01:14 +0000 (UTC)
Message-Id: <201912011601.xB1G14qP007113@ceres.dti.ne.jp>
Date: Mon, 2 Dec 2019 01:01:04 +0900 (JST)
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
Reply-To: tsutsui@ceres.dti.ne.jp
To: gnats-bugs@NetBSD.org
Cc: tsutsui@ceres.dti.ne.jp
Subject: dmesg(8) trims leading whitespaces of kernel messages
X-Send-Pr-Version: 3.95
>Number: 54729
>Category: bin
>Synopsis: dmesg(8) trims leading whitespaces of kernel messages
>Confidential: no
>Severity: non-critical
>Priority: high
>Responsible: tsutsui
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Dec 01 16:05:00 +0000 2019
>Closed-Date: Sun Jan 12 16:04:39 +0000 2020
>Last-Modified: Sun Jan 12 16:04:39 +0000 2020
>Originator: Izumi Tsutsui
>Release: NetBSD 9.0_RC1
>Organization:
>Environment:
System: NetBSD evbarm 9.0_RC1
Architecture: maybe all
Machine: maybe all
>Description:
9.0_RC1 dmesg(8) seems to incorrectly trim leading whitespaces
of kernel messages.
My HP T5325 (evbarm-earm on serial console) shows messages at boot on console:
---
[ 1.0000000] NetBSD/evbarm (hpt5325) booting ...
[ 1.0000000] [ Kernel symbol table missing! ]
[ 1.0000000] Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
[ 1.0000000] 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
[ 1.0000000] 2018, 2019 The NetBSD Foundation, Inc. All rights reserved.
[ 1.0000000] Copyright (c) 1982, 1986, 1989, 1991, 1993
[ 1.0000000] The Regents of the University of California. All rights reserved.
[ 1.0000000] NetBSD 9.0_RC1 (HPT5325) #0: Sun Dec 1 23:17:48 JST 2019
[ 1.0000000] tsutsui@mirage:/s/netbsd-9/src/sys/arch/evbarm/compile/HPT5325
[ 1.0000000] total memory = 512 MB
[ 1.0000000] avail memory = 496 MB
:
---
but dmesg(8) shows:
---
[ 1.000000] Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
[ 1.000000] 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
[ 1.000000] 2018, 2019 The NetBSD Foundation, Inc. All rights reserved.
[ 1.000000] Copyright (c) 1982, 1986, 1989, 1991, 1993
[ 1.000000] The Regents of the University of California. All rights reserved.
[ 1.000000] NetBSD 9.0_RC1 (HPT5325) #0: Sun Dec 1 23:17:48 JST 2019
[ 1.000000] tsutsui@mirage:/s/netbsd-9/src/sys/arch/evbarm/compile/HPT5325
[ 1.000000] total memory = 512 MB
[ 1.000000] avail memory = 496 MB
:
---
and /var/run/dmesg.boot (i.e. dmesg -t) also says:
---
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
2018, 2019 The NetBSD Foundation, Inc. All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
The Regents of the University of California. All rights reserved.
NetBSD 9.0_RC1 (HPT5325) #0: Sun Dec 1 23:17:48 JST 2019
tsutsui@mirage:/s/netbsd-9/src/sys/arch/evbarm/compile/HPT5325
total memory = 512 MB
avail memory = 496 MB
:
---
Note /kern/msgbuf shows correctly:
---
[ 1.0000000] Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
[ 1.0000000] 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
[ 1.0000000] 2018, 2019 The NetBSD Foundation, Inc. All rights reserved.
[ 1.0000000] Copyright (c) 1982, 1986, 1989, 1991, 1993
[ 1.0000000] The Regents of the University of California. All rights reserved.
[ 1.0000000] NetBSD 9.0_RC1 (HPT5325) #0: Sun Dec 1 23:17:48 JST 2019
[ 1.0000000] tsutsui@mirage:/s/netbsd-9/src/sys/arch/evbarm/compile/HPT5325
[ 1.0000000] total memory = 512 MB
[ 1.0000000] avail memory = 496 MB
:
---
(By the way, now I wonder how many MD install scripts use /kern/msgbuf
as dmesg..)
>How-To-Repeat:
Boot NetBSD 9.0_RC1 and check console output and /var/run/dmesg.boot.
No leading whitespaces in copyright years and the UCB name
as mentioned above.
>Fix:
N/A
---
Izumi Tsutsui
>Release-Note:
>Audit-Trail:
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/54729: dmesg(8) trims leading whitespaces of kernel messages
Date: Mon, 02 Dec 2019 08:05:30 +0700
This is a side effect of the way that dmesg(8) parses and then
regenerates the timestamp field (in different possible formats).
It is probably possible to fix it to preserve the spaces (after
the first one) after the timestamp if doing so really is important
for something.
kre
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
To: gnats-bugs@netbsd.org
Cc: tsutsui@ceres.dti.ne.jp
Subject: Re: bin/54729: dmesg(8) trims leading whitespaces of kernel messages
Date: Tue, 31 Dec 2019 07:44:10 +0900
> It is probably possible to fix it to preserve the spaces (after
> the first one) after the timestamp
The following diff restores format as pre-timestamp versions.
Index: dmesg.c
===================================================================
RCS file: /cvsroot/src/sbin/dmesg/dmesg.c,v
retrieving revision 1.43
diff -u -p -d -r1.43 dmesg.c
--- dmesg.c 4 Jun 2019 11:59:05 -0000 1.43
+++ dmesg.c 30 Dec 2019 22:32:56 -0000
@@ -157,7 +157,7 @@ main(int argc, char *argv[])
long nsec, fsec;
int scale;
int deltas, quiet, humantime;
- bool frac;
+ bool frac, postts;
static const int bmib[] = { CTL_KERN, KERN_BOOTTIME };
size = sizeof(boottime);
@@ -262,6 +262,7 @@ main(int argc, char *argv[])
*/
#ifndef SMALL
frac = false;
+ postts = false;
scale = 0;
#endif
for (tstamp = 0, newl = 1, log = i = 0, p = bufdata + cur.msg_bufx;
@@ -310,6 +311,7 @@ main(int argc, char *argv[])
ADDC(ch);
ADDC('\0');
tstamp = 0;
+ postts = true;
sec = fsec = 0;
switch (sscanf(tbuf, "[%jd.%ld]", &sec, &fsec)){
case EOF:
@@ -375,8 +377,10 @@ main(int argc, char *argv[])
continue;
#endif
case ' ':
- if (!tstamp)
+ if (!tstamp && postts) {
+ postts = false;
continue;
+ }
/*FALLTHROUGH*/
default:
#ifndef SMALL
---
BTW, is it intentional that timestamp format is different between
kernel (and /kern/msgbuf) and dmesg?
https://nxr.netbsd.org/xref/src/sys/kern/subr_prf.c?r=1.181#506
> 506 n = snprintf(buf, sizeof(buf), "[% 4jd.%.*ld] ",
>> [ 1.0000000] NetBSD 9.0_RC1 (HPT5325) #0: Sun Dec 1 23:17:48 JST 2019
https://nxr.netbsd.org/xref/src/sbin/dmesg/dmesg.c?r=1.43#358
> 358 printf(" %5jd%s", sec, radix);
>> [ 1.000000] NetBSD 9.0_RC1 (HPT5325) #0: Sun Dec 1 23:17:48 JST 2019
---
Izumi Tsutsui
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/54729: dmesg(8) trims leading whitespaces of kernel messages
Date: Tue, 31 Dec 2019 07:23:55 +0700
Date: Mon, 30 Dec 2019 22:45:01 +0000 (UTC)
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
Message-ID: <20191230224501.4EBA77A1D6@mollari.NetBSD.org>
| BTW, is it intentional that timestamp format is different between
| kernel (and /kern/msgbuf) and dmesg?
Yes. Though neither (particularly dmesg) is really complete, the %5jd
vs %4jd difference just reflects the common uses - kernel messages are
appearing all the time (ages after the system booted), dmesg tends to be
used mostly soon after boot, and only sees smaller second counters typically
(and of course, the field with simple expands if needed, so the only effect
is radix alignment).
The intent is/was that the precision of the timestamp be variable (via a
sysctl for the kernel) - but that part has never been implemented, after
some discussion a more or less adequate precision was simply adopted.
Much of what is in dmesg is to cope with that when it appears (and dmesg should
allow output with a different - reduced - precision if desired, but doesn't).
The kernel also always uses '.' as the radix (no locale stuff gets in there)
but dmesg uses whatever is the user's locale's radix character.
kre
From: "Izumi Tsutsui" <tsutsui@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54729 CVS commit: src/sbin/dmesg
Date: Tue, 31 Dec 2019 19:58:56 +0000
Module Name: src
Committed By: tsutsui
Date: Tue Dec 31 19:58:56 UTC 2019
Modified Files:
src/sbin/dmesg: dmesg.c
Log Message:
Fix dmesg(8) to preserve leading whitespaces of kernel messages.
Closes PR/54729.
To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sbin/dmesg/dmesg.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Responsible-Changed-From-To: bin-bug-people->tsutsui
Responsible-Changed-By: tsutsui@NetBSD.org
Responsible-Changed-When: Tue, 31 Dec 2019 20:16:19 +0000
Responsible-Changed-Why:
I've committed a fix.
State-Changed-From-To: open->needs-pullups
State-Changed-By: tsutsui@NetBSD.org
State-Changed-When: Tue, 31 Dec 2019 20:16:19 +0000
State-Changed-Why:
I'll send a pullup request later.
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54729 CVS commit: [netbsd-9] src/sbin/dmesg
Date: Sun, 5 Jan 2020 09:32:10 +0000
Module Name: src
Committed By: martin
Date: Sun Jan 5 09:32:10 UTC 2020
Modified Files:
src/sbin/dmesg [netbsd-9]: dmesg.c
Log Message:
Pull up following revision(s) (requested by tsutsui in ticket #601):
sbin/dmesg/dmesg.c: revision 1.44
sbin/dmesg/dmesg.c: revision 1.45
Fix dmesg(8) to preserve leading whitespaces of kernel messages.
Closes PR/54729.
Make recent change build for SMALL builds as well as normal ones.
To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.43.2.1 src/sbin/dmesg/dmesg.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: needs-pullups->closed
State-Changed-By: tsutsui@NetBSD.org
State-Changed-When: Sun, 12 Jan 2020 16:04:39 +0000
State-Changed-Why:
Pulled up via [pullup-9 #601].
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.