kern/144307: ENOENT set unnecessarily under certain
circumstances when malloc is called / fails
Jaakko Heinonen
jh at FreeBSD.org
Mon Jun 28 19:10:03 UTC 2010
The following reply was made to PR kern/144307; it has been noted by GNATS.
From: Jaakko Heinonen <jh at FreeBSD.org>
To: Garrett Cooper <gcooper at FreeBSD.org>
Cc: bug-followup at FreeBSD.org
Subject: Re: kern/144307: ENOENT set unnecessarily under certain
circumstances when malloc is called / fails
Date: Mon, 28 Jun 2010 22:05:40 +0300
On 2010-02-26, Garrett Cooper wrote:
> On systems where /etc/malloc.conf isn't present, some failures
> syscalls like read will fail incorrectly with ENOENT because the file
> doesn't exist, and thus output via errx will be incorrect, like shown
I think you mean err(3), not errx(3).
> from the following disklabel output:
>
> 1+0 records in
> 1+0 records out
> 512 bytes transferred in 0.000054 secs (9502140 bytes/sec)
> disklabel: /dev/md1 read: No such file or directory
It's a disklabel bug to inspect the errno value in the success case.
POSIX states: "The value of errno should only be examined when it is
indicated to be valid by a function's return value." and "The setting of
errno after a successful call to a function is unspecified unless the
description of that function specifies that errno shall not be
modified.".
This patch for bsdlabel(8) might fix the error message:
%%%
Index: sbin/bsdlabel/bsdlabel.c
===================================================================
--- sbin/bsdlabel/bsdlabel.c (revision 209580)
+++ sbin/bsdlabel/bsdlabel.c (working copy)
@@ -312,7 +312,7 @@ static void
fixlabel(struct disklabel *lp)
{
struct partition *dp;
- int i;
+ ssize_t i;
for (i = 0; i < lp->d_npartitions; i++) {
if (i == RAW_PART)
@@ -359,8 +359,11 @@ readboot(void)
fstat(fd, &st);
if (alphacksum && st.st_size <= BBSIZE - 512) {
i = read(fd, bootarea + 512, st.st_size);
- if (i != st.st_size)
+ if (i == -1)
err(1, "read error %s", xxboot);
+ if (i != st.st_size)
+ errx(1, "couldn't read %ju bytes from %s",
+ (uintmax_t)st.st_size, xxboot);
/*
* Set the location and length so SRM can find the
@@ -373,8 +376,11 @@ readboot(void)
return;
} else if ((!alphacksum) && st.st_size <= BBSIZE) {
i = read(fd, bootarea, st.st_size);
- if (i != st.st_size)
+ if (i == -1)
err(1, "read error %s", xxboot);
+ if (i != st.st_size)
+ errx(1, "couldn't read %ju bytes from %s",
+ (uintmax_t)st.st_size, xxboot);
return;
}
errx(1, "boot code %s is wrong size", xxboot);
@@ -499,7 +505,7 @@ readlabel(int flag)
"disks with more than 2^32-1 sectors are not supported");
(void)lseek(f, (off_t)0, SEEK_SET);
if (read(f, bootarea, BBSIZE) != BBSIZE)
- err(4, "%s read", specname);
+ errx(4, "couldn't read %d bytes from %s", BBSIZE, specname);
close (f);
error = bsd_disklabel_le_dec(
bootarea + (labeloffset + labelsoffset * secsize),
%%%
--
Jaakko
More information about the freebsd-bugs
mailing list