From MAILER-DAEMON Mon Jul 04 05:28:07 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bK0Ah-0004ll-6r
	for mharc-dmidecode-devel@gnu.org; Mon, 04 Jul 2016 05:28:07 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:60031)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jdelvare@suse.de>) id 1bK0Af-0004lf-Cp
	for dmidecode-devel@nongnu.org; Mon, 04 Jul 2016 05:28:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jdelvare@suse.de>) id 1bK0Aa-0001Ai-Ah
	for dmidecode-devel@nongnu.org; Mon, 04 Jul 2016 05:28:04 -0400
Received: from mx2.suse.de ([195.135.220.15]:54290)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jdelvare@suse.de>) id 1bK0Aa-0001Ad-3f
	for dmidecode-devel@nongnu.org; Mon, 04 Jul 2016 05:28:00 -0400
X-Virus-Scanned: by amavisd-new at test-mx.suse.de
Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254])
	by mx2.suse.de (Postfix) with ESMTP id D1620AB9D;
	Mon,  4 Jul 2016 09:27:58 +0000 (UTC)
Date: Mon, 4 Jul 2016 11:27:57 +0200
From: Jean Delvare <jdelvare@suse.de>
To: dmidecode-devel@nongnu.org
Cc: Roy Franz <roy.franz@linaro.org>
Message-ID: <20160704112757.5302ed46@endymion>
Organization: SUSE Linux
X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.30; x86_64-suse-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no
	timestamps) [generic]
X-Received-From: 195.135.220.15
Subject: [dmidecode] [PATCH] dmidecode: Clarify error message on table read
 failure
X-BeenThere: dmidecode-devel@nongnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <dmidecode-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/dmidecode-devel>, 
	<mailto:dmidecode-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <http://lists.nongnu.org/archive/html/dmidecode-devel/>
List-Post: <mailto:dmidecode-devel@nongnu.org>
List-Help: <mailto:dmidecode-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/dmidecode-devel>,
	<mailto:dmidecode-devel-request@nongnu.org?subject=subscribe>
X-List-Received-Date: Mon, 04 Jul 2016 09:28:06 -0000

Stop using the term "unreachable" when the DMI table can't be read. It
originates from the /dev/mem access method, but no longer makes sense
when reading from sysfs or from a binary dump file.

Also don't suggest building with -DUSE_MMAP if reading from sysfs, as
it wouldn't help anyway.
---
 dmidecode.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--- dmidecode.orig/dmidecode.c	2016-06-30 11:50:30.501728766 +0200
+++ dmidecode/dmidecode.c	2016-07-04 11:19:02.350581000 +0200
@@ -4550,11 +4550,12 @@ static void dmi_table(off_t base, u32 le
 
 	if (buf == NULL)
 	{
-		fprintf(stderr, "Table is unreachable, sorry."
+		fprintf(stderr, "Failed to read table, sorry.\n");
 #ifndef USE_MMAP
-			" Try compiling dmidecode with -DUSE_MMAP."
+		if (!(flags & FLAG_NO_FILE_OFFSET))
+			fprintf(stderr,
+				"Try compiling dmidecode with -DUSE_MMAP.\n");
 #endif
-			"\n");
 		return;
 	}
 


-- 
Jean Delvare
SUSE L3 Support


From MAILER-DAEMON Mon Jul 04 06:12:47 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bK0rv-0004Zg-Lz
	for mharc-dmidecode-devel@gnu.org; Mon, 04 Jul 2016 06:12:47 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:44400)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jdelvare@suse.de>) id 1bK0rt-0004YJ-BR
	for dmidecode-devel@nongnu.org; Mon, 04 Jul 2016 06:12:46 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jdelvare@suse.de>) id 1bK0ro-0002iP-Aa
	for dmidecode-devel@nongnu.org; Mon, 04 Jul 2016 06:12:45 -0400
Received: from mx2.suse.de ([195.135.220.15]:59809)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jdelvare@suse.de>) id 1bK0rn-0002iA-Ul
	for dmidecode-devel@nongnu.org; Mon, 04 Jul 2016 06:12:40 -0400
X-Virus-Scanned: by amavisd-new at test-mx.suse.de
Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254])
	by mx2.suse.de (Postfix) with ESMTP id 49064AB9D;
	Mon,  4 Jul 2016 10:12:38 +0000 (UTC)
Date: Mon, 4 Jul 2016 12:12:37 +0200
From: Jean Delvare <jdelvare@suse.de>
To: Kevin Bowling <kevin.bowling@kev009.com>
Cc: dmidecode-devel@nongnu.org
Message-ID: <20160704121237.6a32e5aa@endymion>
In-Reply-To: <CAK7dMtBOZvFm4vDQJ2sv0VDAz9f=DGOfv=xnumqSyTv_M7yVAA@mail.gmail.com>
References: <CAK7dMtBOZvFm4vDQJ2sv0VDAz9f=DGOfv=xnumqSyTv_M7yVAA@mail.gmail.com>
Organization: SUSE Linux
X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.30; x86_64-suse-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no
	timestamps) [generic]
X-Received-From: 195.135.220.15
Subject: Re: [dmidecode] [patch #8989] Output "Invalid entry length.. Fixed
 up" warning to stderr
X-BeenThere: dmidecode-devel@nongnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <dmidecode-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/dmidecode-devel>, 
	<mailto:dmidecode-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <http://lists.nongnu.org/archive/html/dmidecode-devel/>
List-Post: <mailto:dmidecode-devel@nongnu.org>
List-Help: <mailto:dmidecode-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/dmidecode-devel>,
	<mailto:dmidecode-devel-request@nongnu.org?subject=subscribe>
X-List-Received-Date: Mon, 04 Jul 2016 10:12:46 -0000

Hi Kevin,

On Thu, 28 Apr 2016 18:56:26 -0700, Kevin Bowling wrote:
> dmidecode 3.0 breaks DMI values of some tools like SaltStack that read
> stdout for specific values to populate data structures about a host on some
> hardware because of a warning like "Invalid entry length (16). Fixed up to
> 11."
> 
> My proposed fix is to simply move it to stderr
> http://savannah.nongnu.org/patch/?8989

I've generalized it after seeing another related bug report. Can you
try the following patch?

From: Jean Delvare <jdelvare@suse.de>
Subject: dmidecode: Move error messages to stderr

Consistently write error messages to stderr, to avoid messing up the
output of "dmidecode -s". Based on preliminary patches by
Kevin Bowling and Simon Rettberg.

Fixes bug #47274:
https://savannah.nongnu.org/bugs/?47274
Fixes bug #48158:
https://savannah.nongnu.org/bugs/?48158
Supersedes patch #8989:
https://savannah.nongnu.org/patch/?8989
---
 dmidecode.c |   37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

--- dmidecode.orig/dmidecode.c	2016-07-04 11:36:36.961481311 +0200
+++ dmidecode/dmidecode.c	2016-07-04 12:06:51.529344282 +0200
@@ -2958,7 +2958,8 @@ static void dmi_fixup_type_34(struct dmi
 	 && is_printable(p + 0x0B, 0x10 - 0x0B))
 	{
 		if (!(opt.flags & FLAG_QUIET) && display)
-			printf("Invalid entry length (%u). Fixed up to %u.\n",
+			fprintf(stderr,
+				"Invalid entry length (%u). Fixed up to %u.\n",
 				0x10, 0x0B);
 		h->length = 0x0B;
 	}
@@ -4427,9 +4428,14 @@ static void dmi_table_decode(u8 *buf, u3
 		 */
 		if (h.length < 4)
 		{
-			printf("Invalid entry length (%u). DMI table is "
-			       "broken! Stop.\n\n", (unsigned int)h.length);
-			opt.flags |= FLAG_QUIET;
+			if (!(opt.flags & FLAG_QUIET))
+			{
+				fprintf(stderr,
+					"Invalid entry length (%u). DMI table "
+					"is broken! Stop.\n\n",
+					(unsigned int)h.length);
+				opt.flags |= FLAG_QUIET;
+			}
 			break;
 		}
 
@@ -4490,11 +4496,11 @@ static void dmi_table_decode(u8 *buf, u3
 	if (!(opt.flags & FLAG_QUIET))
 	{
 		if (num && i != num)
-			printf("Wrong DMI structures count: %d announced, "
+			fprintf(stderr, "Wrong DMI structures count: %d announced, "
 				"only %d decoded.\n", num, i);
 		if ((unsigned long)(data - buf) > len
 		 || (num && (unsigned long)(data - buf) < len))
-			printf("Wrong DMI structures length: %u bytes "
+			fprintf(stderr, "Wrong DMI structures length: %u bytes "
 				"announced, structures occupy %lu bytes.\n",
 				len, (unsigned long)(data - buf));
 	}
@@ -4539,7 +4545,7 @@ static void dmi_table(off_t base, u32 le
 		buf = read_file(&size, devmem);
 		if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)len)
 		{
-			printf("Wrong DMI structures length: %u bytes "
+			fprintf(stderr, "Wrong DMI structures length: %u bytes "
 				"announced, only %lu bytes available.\n",
 				len, (unsigned long)size);
 		}
@@ -4652,14 +4658,16 @@ static int smbios_decode(u8 *buf, const
 		case 0x021F:
 		case 0x0221:
 			if (!(opt.flags & FLAG_QUIET))
-				printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
-				       ver & 0xFF, 3);
+				fprintf(stderr,
+					"SMBIOS version fixup (2.%d -> 2.%d).\n",
+					ver & 0xFF, 3);
 			ver = 0x0203;
 			break;
 		case 0x0233:
 			if (!(opt.flags & FLAG_QUIET))
-				printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
-				       51, 6);
+				fprintf(stderr,
+					"SMBIOS version fixup (2.%d -> 2.%d).\n",
+					51, 6);
 			ver = 0x0206;
 			break;
 	}
@@ -4771,6 +4779,13 @@ int main(int argc, char * const argv[])
 	int efi;
 	u8 *buf;
 
+	/*
+	 * We don't want stdout and stderr to be mixed up if both are
+	 * redirected to the same file.
+	 */
+	setlinebuf(stdout);
+	setlinebuf(stderr);
+
 	if (sizeof(u8) != 1 || sizeof(u16) != 2 || sizeof(u32) != 4 || '\0' != 0)
 	{
 		fprintf(stderr, "%s: compiler incompatibility\n", argv[0]);


-- 
Jean Delvare
SUSE L3 Support


From MAILER-DAEMON Mon Jul 04 10:11:52 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bK4bI-0004bp-MK
	for mharc-dmidecode-devel@gnu.org; Mon, 04 Jul 2016 10:11:52 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39564)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <kevin.bowling@kev009.com>) id 1bK4bC-0004X0-Ky
	for dmidecode-devel@nongnu.org; Mon, 04 Jul 2016 10:11:51 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <kevin.bowling@kev009.com>) id 1bK4b9-0001q2-HG
	for dmidecode-devel@nongnu.org; Mon, 04 Jul 2016 10:11:45 -0400
Received: from mail-oi0-x243.google.com ([2607:f8b0:4003:c06::243]:34132)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <kevin.bowling@kev009.com>) id 1bK4b9-0001py-7r
	for dmidecode-devel@nongnu.org; Mon, 04 Jul 2016 10:11:43 -0400
Received: by mail-oi0-x243.google.com with SMTP id s17so23397889oih.1
	for <dmidecode-devel@nongnu.org>; Mon, 04 Jul 2016 07:11:42 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kev009.com; s=google;
	h=mime-version:in-reply-to:references:from:date:message-id:subject:to
	:cc; bh=vVpFPhuBL0cZEEoWaNER5zCe0DmqPA3oAE6ucECtkRI=;
	b=ILWOk5MvJBt+1O1CQ5242Y+W8rdpIfhoZhzRF8QBd4ERViUDWogEzAI2E3MZcbTQGz
	p1ebMclWsPd4CGT3f/RJ6yjNFZuMQ7BiUZEfABX0Re8hM4VaXviHzWRVkb1EHdy4PZYb
	KtoTiJ+fN7WBZgM4Y3gFQxMNNihAcPODG0BOk=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20130820;
	h=x-gm-message-state:mime-version:in-reply-to:references:from:date
	:message-id:subject:to:cc;
	bh=vVpFPhuBL0cZEEoWaNER5zCe0DmqPA3oAE6ucECtkRI=;
	b=GrAgTZSGWXuaKns2JbOXLMzZQuXUpIK/OKmR1k4A1O2r0X0h6IT6iAjmP6zWZX+1Qn
	wZVyU2ME8sBGDUw1rEh07TMIaIhike18YV+DIwe+vGc+KMV8pD72c7U8Rpf1QzbfZArI
	/5R1UrJuOSCWBuGdCX3OxVAREuWq4KF5KRlDWgaqr+bLYznvf54/mB03zGK7yP9yt9QZ
	aMiuCsBRGft3kf/b8YuLJ1+6NKowOrXdEFMjOup+9k4jJq5VEUzEiGlBm+6vEdk/2aJg
	QucnJizqRwDCxWi5qZzximRY17E00XA1Vmki/AU/eGiwtBZ3djQhF7T/F2EraFwrQslH
	kd3g==
X-Gm-Message-State: ALyK8tIMmyIsI/FrcDb5jnb0nzvvhNa8/ua062FSHB9gKtvOYv5Rr+W5rbFlTSHU058l4SJrOclduL4XfKO/uA==
X-Received: by 10.202.79.66 with SMTP id d63mr7073572oib.5.1467641502210; Mon,
	04 Jul 2016 07:11:42 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.157.17.178 with HTTP; Mon, 4 Jul 2016 07:11:41 -0700 (PDT)
In-Reply-To: <20160704121237.6a32e5aa@endymion>
References: <CAK7dMtBOZvFm4vDQJ2sv0VDAz9f=DGOfv=xnumqSyTv_M7yVAA@mail.gmail.com>
	<20160704121237.6a32e5aa@endymion>
From: Kevin Bowling <kevin.bowling@kev009.com>
Date: Mon, 4 Jul 2016 07:11:41 -0700
Message-ID: <CAK7dMtD3KPiJUuDEJxODPfYmbedL5ZNsKsGgTYuT+g7-Df6d1w@mail.gmail.com>
To: Jean Delvare <jdelvare@suse.de>
Cc: dmidecode-devel@nongnu.org
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2607:f8b0:4003:c06::243
Content-Type: text/plain; charset=UTF-8
X-Content-Filtered-By: Mailman/MimeDel 2.1.21
Subject: Re: [dmidecode] [patch #8989] Output "Invalid entry length.. Fixed
 up" warning to stderr
X-BeenThere: dmidecode-devel@nongnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <dmidecode-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/dmidecode-devel>, 
	<mailto:dmidecode-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <http://lists.nongnu.org/archive/html/dmidecode-devel/>
List-Post: <mailto:dmidecode-devel@nongnu.org>
List-Help: <mailto:dmidecode-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/dmidecode-devel>,
	<mailto:dmidecode-devel-request@nongnu.org?subject=subscribe>
X-List-Received-Date: Mon, 04 Jul 2016 14:11:51 -0000

Thanks, this looks good to me.

Regards,
Kevin

On Mon, Jul 4, 2016 at 3:12 AM, Jean Delvare <jdelvare@suse.de> wrote:

> Hi Kevin,
>
> On Thu, 28 Apr 2016 18:56:26 -0700, Kevin Bowling wrote:
> > dmidecode 3.0 breaks DMI values of some tools like SaltStack that read
> > stdout for specific values to populate data structures about a host on
> some
> > hardware because of a warning like "Invalid entry length (16). Fixed up
> to
> > 11."
> >
> > My proposed fix is to simply move it to stderr
> > http://savannah.nongnu.org/patch/?8989
>
> I've generalized it after seeing another related bug report. Can you
> try the following patch?
>
> From: Jean Delvare <jdelvare@suse.de>
> Subject: dmidecode: Move error messages to stderr
>
> Consistently write error messages to stderr, to avoid messing up the
> output of "dmidecode -s". Based on preliminary patches by
> Kevin Bowling and Simon Rettberg.
>
> Fixes bug #47274:
> https://savannah.nongnu.org/bugs/?47274
> Fixes bug #48158:
> https://savannah.nongnu.org/bugs/?48158
> Supersedes patch #8989:
> https://savannah.nongnu.org/patch/?8989
> ---
>  dmidecode.c |   37 ++++++++++++++++++++++++++-----------
>  1 file changed, 26 insertions(+), 11 deletions(-)
>
> --- dmidecode.orig/dmidecode.c  2016-07-04 11:36:36.961481311 +0200
> +++ dmidecode/dmidecode.c       2016-07-04 12:06:51.529344282 +0200
> @@ -2958,7 +2958,8 @@ static void dmi_fixup_type_34(struct dmi
>          && is_printable(p + 0x0B, 0x10 - 0x0B))
>         {
>                 if (!(opt.flags & FLAG_QUIET) && display)
> -                       printf("Invalid entry length (%u). Fixed up to
> %u.\n",
> +                       fprintf(stderr,
> +                               "Invalid entry length (%u). Fixed up to
> %u.\n",
>                                 0x10, 0x0B);
>                 h->length = 0x0B;
>         }
> @@ -4427,9 +4428,14 @@ static void dmi_table_decode(u8 *buf, u3
>                  */
>                 if (h.length < 4)
>                 {
> -                       printf("Invalid entry length (%u). DMI table is "
> -                              "broken! Stop.\n\n", (unsigned
> int)h.length);
> -                       opt.flags |= FLAG_QUIET;
> +                       if (!(opt.flags & FLAG_QUIET))
> +                       {
> +                               fprintf(stderr,
> +                                       "Invalid entry length (%u). DMI
> table "
> +                                       "is broken! Stop.\n\n",
> +                                       (unsigned int)h.length);
> +                               opt.flags |= FLAG_QUIET;
> +                       }
>                         break;
>                 }
>
> @@ -4490,11 +4496,11 @@ static void dmi_table_decode(u8 *buf, u3
>         if (!(opt.flags & FLAG_QUIET))
>         {
>                 if (num && i != num)
> -                       printf("Wrong DMI structures count: %d announced, "
> +                       fprintf(stderr, "Wrong DMI structures count: %d
> announced, "
>                                 "only %d decoded.\n", num, i);
>                 if ((unsigned long)(data - buf) > len
>                  || (num && (unsigned long)(data - buf) < len))
> -                       printf("Wrong DMI structures length: %u bytes "
> +                       fprintf(stderr, "Wrong DMI structures length: %u
> bytes "
>                                 "announced, structures occupy %lu
> bytes.\n",
>                                 len, (unsigned long)(data - buf));
>         }
> @@ -4539,7 +4545,7 @@ static void dmi_table(off_t base, u32 le
>                 buf = read_file(&size, devmem);
>                 if (!(opt.flags & FLAG_QUIET) && num && size !=
> (size_t)len)
>                 {
> -                       printf("Wrong DMI structures length: %u bytes "
> +                       fprintf(stderr, "Wrong DMI structures length: %u
> bytes "
>                                 "announced, only %lu bytes available.\n",
>                                 len, (unsigned long)size);
>                 }
> @@ -4652,14 +4658,16 @@ static int smbios_decode(u8 *buf, const
>                 case 0x021F:
>                 case 0x0221:
>                         if (!(opt.flags & FLAG_QUIET))
> -                               printf("SMBIOS version fixup (2.%d ->
> 2.%d).\n",
> -                                      ver & 0xFF, 3);
> +                               fprintf(stderr,
> +                                       "SMBIOS version fixup (2.%d ->
> 2.%d).\n",
> +                                       ver & 0xFF, 3);
>                         ver = 0x0203;
>                         break;
>                 case 0x0233:
>                         if (!(opt.flags & FLAG_QUIET))
> -                               printf("SMBIOS version fixup (2.%d ->
> 2.%d).\n",
> -                                      51, 6);
> +                               fprintf(stderr,
> +                                       "SMBIOS version fixup (2.%d ->
> 2.%d).\n",
> +                                       51, 6);
>                         ver = 0x0206;
>                         break;
>         }
> @@ -4771,6 +4779,13 @@ int main(int argc, char * const argv[])
>         int efi;
>         u8 *buf;
>
> +       /*
> +        * We don't want stdout and stderr to be mixed up if both are
> +        * redirected to the same file.
> +        */
> +       setlinebuf(stdout);
> +       setlinebuf(stderr);
> +
>         if (sizeof(u8) != 1 || sizeof(u16) != 2 || sizeof(u32) != 4 ||
> '\0' != 0)
>         {
>                 fprintf(stderr, "%s: compiler incompatibility\n", argv[0]);
>
>
> --
> Jean Delvare
> SUSE L3 Support
>

