Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7461463

Browse files
committed
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
1 parent dcbff06 commit 7461463

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

‎dmidecode.c‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,8 @@ static void dmi_fixup_type_34(struct dmi_header *h, int display)
29582958
&& is_printable(p + 0x0B, 0x10 - 0x0B))
29592959
{
29602960
if (!(opt.flags & FLAG_QUIET) && display)
2961-
printf("Invalid entry length (%u). Fixed up to %u.\n",
2961+
fprintf(stderr,
2962+
"Invalid entry length (%u). Fixed up to %u.\n",
29622963
0x10, 0x0B);
29632964
h->length = 0x0B;
29642965
}
@@ -4427,9 +4428,14 @@ static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
44274428
*/
44284429
if (h.length < 4)
44294430
{
4430-
printf("Invalid entry length (%u). DMI table is "
4431-
"broken! Stop.\n\n", (unsigned int)h.length);
4432-
opt.flags |= FLAG_QUIET;
4431+
if (!(opt.flags & FLAG_QUIET))
4432+
{
4433+
fprintf(stderr,
4434+
"Invalid entry length (%u). DMI table "
4435+
"is broken! Stop.\n\n",
4436+
(unsigned int)h.length);
4437+
opt.flags |= FLAG_QUIET;
4438+
}
44334439
break;
44344440
}
44354441

@@ -4490,11 +4496,11 @@ static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
44904496
if (!(opt.flags & FLAG_QUIET))
44914497
{
44924498
if (num && i != num)
4493-
printf("Wrong DMI structures count: %d announced, "
4499+
fprintf(stderr, "Wrong DMI structures count: %d announced, "
44944500
"only %d decoded.\n", num, i);
44954501
if ((unsigned long)(data - buf) > len
44964502
|| (num && (unsigned long)(data - buf) < len))
4497-
printf("Wrong DMI structures length: %u bytes "
4503+
fprintf(stderr, "Wrong DMI structures length: %u bytes "
44984504
"announced, structures occupy %lu bytes.\n",
44994505
len, (unsigned long)(data - buf));
45004506
}
@@ -4539,7 +4545,7 @@ static void dmi_table(off_t base, u32 len, u16 num, u16 ver, const char *devmem,
45394545
buf = read_file(&size, devmem);
45404546
if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)len)
45414547
{
4542-
printf("Wrong DMI structures length: %u bytes "
4548+
fprintf(stderr, "Wrong DMI structures length: %u bytes "
45434549
"announced, only %lu bytes available.\n",
45444550
len, (unsigned long)size);
45454551
}
@@ -4652,14 +4658,16 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
46524658
case 0x021F:
46534659
case 0x0221:
46544660
if (!(opt.flags & FLAG_QUIET))
4655-
printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
4656-
ver & 0xFF, 3);
4661+
fprintf(stderr,
4662+
"SMBIOS version fixup (2.%d -> 2.%d).\n",
4663+
ver & 0xFF, 3);
46574664
ver = 0x0203;
46584665
break;
46594666
case 0x0233:
46604667
if (!(opt.flags & FLAG_QUIET))
4661-
printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
4662-
51, 6);
4668+
fprintf(stderr,
4669+
"SMBIOS version fixup (2.%d -> 2.%d).\n",
4670+
51, 6);
46634671
ver = 0x0206;
46644672
break;
46654673
}
@@ -4771,6 +4779,13 @@ int main(int argc, char * const argv[])
47714779
int efi;
47724780
u8 *buf;
47734781

4782+
/*
4783+
* We don't want stdout and stderr to be mixed up if both are
4784+
* redirected to the same file.
4785+
*/
4786+
setlinebuf(stdout);
4787+
setlinebuf(stderr);
4788+
47744789
if (sizeof(u8) != 1 || sizeof(u16) != 2 || sizeof(u32) != 4 || '0円' != 0)
47754790
{
47764791
fprintf(stderr, "%s: compiler incompatibility\n", argv[0]);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /