[PATCH] makedumpfile: Fix dmesg format after crash utility

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 1 Sep 2014 06:36:55 +0000
Atsushi Kumagai <kumagai-atsushi at mxc.nes.nec.co.jp> wrote:

> Hello Petr,
> 
> >On Fri, 29 Aug 2014 01:43:31 +0000
> >Atsushi Kumagai <kumagai-atsushi at mxc.nes.nec.co.jp> wrote:
> >
> >> Hello,
> >
> >Hello Kumagai-san,
> >
> >> I made a trivial patch for v1.5.7.
> >> This isn't essential but it's better than nothing.
> >>[...]
> >> diff --git a/makedumpfile.c b/makedumpfile.c
> >> index b4b6eca..632daba 100644
> >> --- a/makedumpfile.c
> >> +++ b/makedumpfile.c
> >> @@ -3950,6 +3950,7 @@ dump_log_entry(char *logptr, int fp)
> >>  {
> >>  	char *msg, *p, *bufp;
> >>  	unsigned int i, text_len;
> >> +	unsigned int indent_len;
> >>  	unsigned long long ts_nsec;
> >>  	char buf[BUFSIZE];
> >>  	ulonglong nanos;
> >> @@ -3965,6 +3966,7 @@ dump_log_entry(char *logptr, int fp)
> >>
> >>  	bufp = buf;
> >>  	bufp += sprintf(buf, "[%5lld.%06ld] ", nanos, rem/1000);
> >> +	indent_len = strlen(buf);
> >>
> >>  	for (i = 0, p = msg; i < text_len; i++, p++) {
> >>  		/* 6bytes = "\\x%02x" + '\n' + '\0' */
> >> @@ -3974,7 +3976,9 @@ dump_log_entry(char *logptr, int fp)
> >>  			bufp = buf;
> >>  		}
> >>
> >> -		if (isprint(*p) || isspace(*p))
> >> +		if (*p == '\n')
> >> +			bufp += sprintf(bufp, "\n%-*s", indent_len, "");
> >> +		else if (isprint(*p) || isspace(*p))
> >
> >If you do this, you'll have to adjust the condition for growing the buffer above:
> >
> >	if (bufp - buf >= sizeof(buf) - 6) {
> 
> Yeah, I missed this.
> 
> >Let me send a cleanup patch for the "magic constant", which was never a
> >good idea, it seems.
> 
> I've written the v2 patch based on your cleanup.

This one looks perfect. Good job!

Petr Tesarik
SUSE L3 Team 1

> Thanks
> Atsushi Kumagai
> 
> From: Atsushi Kumagai <kumagai-atsushi at mxc.nes.nec.co.jp>
> Date: Mon, 1 Sep 2014 14:23:01 +0900
> Subject: [PATCH v2] Fix dmesg format after crash utility.
> 
> Add some spaces before a new line as much as the length
> of the timestamp like crash utility as:
> 
>     $ diff -u  current.dmesg fixed.dmesg
>     --- current.dmesg       2014-08-28 17:39:53.000000000 +0900
>     +++ fixed.dmesg 2014-08-27 16:46:09.000000000 +0900
>     @@ -150,8 +150,8 @@
>      [    0.015251] Disabled fast string operations
>      [    0.015285] mce: CPU supports 10 MCE banks
>      [    0.015402] Last level iTLB entries: 4KB 0, 2MB 0, 4MB 0
>     -Last level dTLB entries: 4KB 0, 2MB 0, 4MB 0, 1GB 0
>     -tlb_flushall_shift: 6
>     +               Last level dTLB entries: 4KB 0, 2MB 0, 4MB 0, 1GB 0
>     +               tlb_flushall_shift: 6
>      [    0.015535] Freeing SMP alternatives memory: 20K (ffffffff81964000 - ffffffff81969000)
>      [    0.018265] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
>      [    0.028286] smpboot: CPU0: Intel QEMU Virtual CPU version (cpu64-rhel6) (fam: 06, model: 0d, stepping: 03)
>     $
> 
> Signed-off-by: Atsushi Kumagai <kumagai-atsushi at mxc.nes.nec.co.jp>
> ---
>  makedumpfile.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/makedumpfile.c b/makedumpfile.c
> index 37dea37..0a50175 100644
> --- a/makedumpfile.c
> +++ b/makedumpfile.c
> @@ -3949,7 +3949,7 @@ static int
>  dump_log_entry(char *logptr, int fp)
>  {
>  	char *msg, *p, *bufp;
> -	unsigned int i, text_len, buf_need;
> +	unsigned int i, text_len, indent_len, buf_need;
>  	unsigned long long ts_nsec;
>  	char buf[BUFSIZE];
>  	ulonglong nanos;
> @@ -3965,9 +3965,10 @@ dump_log_entry(char *logptr, int fp)
>  
>  	bufp = buf;
>  	bufp += sprintf(buf, "[%5lld.%06ld] ", nanos, rem/1000);
> +	indent_len = strlen(buf);
>  
>  	/* How much buffer space is needed in the worst case */
> -	buf_need = sizeof("\\xXX\n");
> +	buf_need = MAX(sizeof("\\xXX\n"), sizeof("\n") + indent_len);
>  
>  	for (i = 0, p = msg; i < text_len; i++, p++) {
>  		if (bufp - buf >= sizeof(buf) - buf_need) {
> @@ -3976,7 +3977,9 @@ dump_log_entry(char *logptr, int fp)
>  			bufp = buf;
>  		}
>  
> -		if (isprint(*p) || isspace(*p))
> +		if (*p == '\n')
> +			bufp += sprintf(bufp, "\n%-*s", indent_len, "");
> +		else if (isprint(*p) || isspace(*p))
>  			*bufp++ = *p;
>  		else
>  			bufp += sprintf(bufp, "\\x%02x", *p);




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux