nanxiongchao / rpms / dmidecode

Forked from rpms/dmidecode 4 years ago
Clone

Blame SOURCES/0004-dmidecode-Move-error-messages-to-stderr.patch

94a757
From 74614633b31a2ac01240c72890722a86a3f3fc97 Mon Sep 17 00:00:00 2001
94a757
From: Jean Delvare <jdelvare@suse.de>
94a757
Date: Fri, 22 Jul 2016 10:26:50 +0200
94a757
Subject: [PATCH 4/9] dmidecode: Move error messages to stderr
94a757
94a757
Consistently write error messages to stderr, to avoid messing up the
94a757
output of "dmidecode -s". Based on preliminary patches by
94a757
Kevin Bowling and Simon Rettberg.
94a757
94a757
Fixes bug #47274:
94a757
https://savannah.nongnu.org/bugs/?47274
94a757
Fixes bug #48158:
94a757
https://savannah.nongnu.org/bugs/?48158
94a757
Supersedes patch #8989:
94a757
https://savannah.nongnu.org/patch/?8989
94a757
---
94a757
 dmidecode.c | 37 ++++++++++++++++++++++++++-----------
94a757
 1 file changed, 26 insertions(+), 11 deletions(-)
94a757
94a757
diff --git a/dmidecode.c b/dmidecode.c
94a757
index ffd916c..f56d0c5 100644
94a757
--- a/dmidecode.c
94a757
+++ b/dmidecode.c
94a757
@@ -2958,7 +2958,8 @@ static void dmi_fixup_type_34(struct dmi_header *h, int display)
94a757
	 && is_printable(p + 0x0B, 0x10 - 0x0B))
94a757
	{
94a757
		if (!(opt.flags & FLAG_QUIET) && display)
94a757
-			printf("Invalid entry length (%u). Fixed up to %u.\n",
94a757
+			fprintf(stderr,
94a757
+				"Invalid entry length (%u). Fixed up to %u.\n",
94a757
				0x10, 0x0B);
94a757
		h->length = 0x0B;
94a757
	}
94a757
@@ -4427,9 +4428,14 @@ static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
94a757
		 */
94a757
		if (h.length < 4)
94a757
		{
94a757
-			printf("Invalid entry length (%u). DMI table is "
94a757
-			       "broken! Stop.\n\n", (unsigned int)h.length);
94a757
-			opt.flags |= FLAG_QUIET;
94a757
+			if (!(opt.flags & FLAG_QUIET))
94a757
+			{
94a757
+				fprintf(stderr,
94a757
+					"Invalid entry length (%u). DMI table "
94a757
+					"is broken! Stop.\n\n",
94a757
+					(unsigned int)h.length);
94a757
+				opt.flags |= FLAG_QUIET;
94a757
+			}
94a757
			break;
94a757
		}
94a757
94a757
@@ -4490,11 +4496,11 @@ static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
94a757
	if (!(opt.flags & FLAG_QUIET))
94a757
	{
94a757
		if (num && i != num)
94a757
-			printf("Wrong DMI structures count: %d announced, "
94a757
+			fprintf(stderr, "Wrong DMI structures count: %d announced, "
94a757
				"only %d decoded.\n", num, i);
94a757
		if ((unsigned long)(data - buf) > len
94a757
		 || (num && (unsigned long)(data - buf) < len))
94a757
-			printf("Wrong DMI structures length: %u bytes "
94a757
+			fprintf(stderr, "Wrong DMI structures length: %u bytes "
94a757
				"announced, structures occupy %lu bytes.\n",
94a757
				len, (unsigned long)(data - buf));
94a757
	}
94a757
@@ -4539,7 +4545,7 @@ static void dmi_table(off_t base, u32 len, u16 num, u16 ver, const char *devmem,
94a757
		buf = read_file(&size, devmem);
94a757
		if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)len)
94a757
		{
94a757
-			printf("Wrong DMI structures length: %u bytes "
94a757
+			fprintf(stderr, "Wrong DMI structures length: %u bytes "
94a757
				"announced, only %lu bytes available.\n",
94a757
				len, (unsigned long)size);
94a757
		}
94a757
@@ -4652,14 +4658,16 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
94a757
		case 0x021F:
94a757
		case 0x0221:
94a757
			if (!(opt.flags & FLAG_QUIET))
94a757
-				printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
94a757
-				       ver & 0xFF, 3);
94a757
+				fprintf(stderr,
94a757
+					"SMBIOS version fixup (2.%d -> 2.%d).\n",
94a757
+					ver & 0xFF, 3);
94a757
			ver = 0x0203;
94a757
			break;
94a757
		case 0x0233:
94a757
			if (!(opt.flags & FLAG_QUIET))
94a757
-				printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
94a757
-				       51, 6);
94a757
+				fprintf(stderr,
94a757
+					"SMBIOS version fixup (2.%d -> 2.%d).\n",
94a757
+					51, 6);
94a757
			ver = 0x0206;
94a757
			break;
94a757
	}
94a757
@@ -4771,6 +4779,13 @@ int main(int argc, char * const argv[])
94a757
	int efi;
94a757
	u8 *buf;
94a757
94a757
+	/*
94a757
+	 * We don't want stdout and stderr to be mixed up if both are
94a757
+	 * redirected to the same file.
94a757
+	 */
94a757
+	setlinebuf(stdout);
94a757
+	setlinebuf(stderr);
94a757
+
94a757
	if (sizeof(u8) != 1 || sizeof(u16) != 2 || sizeof(u32) != 4 || '\0' != 0)
94a757
	{
94a757
		fprintf(stderr, "%s: compiler incompatibility\n", argv[0]);
94a757
--
94a757
2.10.2