Date: Mon, 28 Jun 2010 19:10:03 GMT From: Jaakko Heinonen <jh@FreeBSD.org> To: freebsd-bugs@FreeBSD.org Subject: Re: kern/144307: ENOENT set unnecessarily under certain circumstances when malloc is called / fails Message-ID: <201006281910.o5SJA3xL003167@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/144307; it has been noted by GNATS. From: Jaakko Heinonen <jh@FreeBSD.org> To: Garrett Cooper <gcooper@FreeBSD.org> Cc: bug-followup@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006281910.o5SJA3xL003167>