From owner-freebsd-bugs@FreeBSD.ORG Fri Feb 26 01:20:02 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2DA94106564A for ; Fri, 26 Feb 2010 01:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id E3B028FC1C for ; Fri, 26 Feb 2010 01:20:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id o1Q1K1ZF091719 for ; Fri, 26 Feb 2010 01:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id o1Q1K1px091718; Fri, 26 Feb 2010 01:20:01 GMT (envelope-from gnats) Resent-Date: Fri, 26 Feb 2010 01:20:01 GMT Resent-Message-Id: <201002260120.o1Q1K1px091718@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 70500106566C for ; Fri, 26 Feb 2010 01:16:02 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 0ED698FC1D for ; Fri, 26 Feb 2010 01:16:02 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o1Q1G1bS096819 for ; Fri, 26 Feb 2010 01:16:01 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o1Q1G1mu096818; Fri, 26 Feb 2010 01:16:01 GMT (envelope-from nobody) Message-Id: <201002260116.o1Q1G1mu096818@www.freebsd.org> Date: Fri, 26 Feb 2010 01:16:01 GMT From: Garrett Cooper To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/144307: ENOENT set unnecessarily under certain circumstances when malloc is called / fails X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Feb 2010 01:20:02 -0000 >Number: 144307 >Category: misc >Synopsis: ENOENT set unnecessarily under certain circumstances when malloc is called / fails >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Feb 26 01:20:01 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Garrett Cooper >Release: RELENG_8 >Organization: Cisco Systems, Inc >Environment: FreeBSD garrcoop-fbsd.cisco.com 8.0-STABLE FreeBSD 8.0-STABLE #2: Wed Feb 3 16:57:07 PST 2010 garrcoop@garrcoop-fbsd.cisco.com:/usr/obj/usr/src/sys/LAPPY_X86 i386 >Description: 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 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 This can be reproduced as follows (yes, the dd command are stat commands are wrong -- I know that...) if malloc.conf is not present: dd if=/dev/zero of=$output_file conv=sparse bs=$(stat -f '%z' "$input_directory") count=1 mdconfig -a -t vnode -u ${md_num} -f "$output_file" disklabel -rw /dev/md${md_num} auto Once malloc.conf is present... sudo ln -s M /etc/malloc.conf # ... 1+0 records in 1+0 records out 512 bytes transferred in 0.000054 secs (9460280 bytes/sec) disklabel: /dev/md1 read: Unknown error: 0 >How-To-Repeat: dd if=/dev/zero of=foo conv=sparse bs=512 count=1 mdconfig -a -t vnode -u 1 -f foo disklabel -rw /dev/md1 auto >Fix: 1. Set malloc.conf to a valid value as per malloc(3). 2. Apply attached patch. Patch attached with submission follows: Index: lib/libc/stdlib/malloc.c =================================================================== --- lib/libc/stdlib/malloc.c (revision 204027) +++ lib/libc/stdlib/malloc.c (working copy) @@ -5408,6 +5408,11 @@ /* Get runtime configuration. */ switch (i) { case 0: + /* + * Make sure that a valid errno code doesn't get wiped + * out if malloc.conf doesn't exist. + */ + int saved_errno = errno; if ((linklen = readlink("/etc/malloc.conf", buf, sizeof(buf) - 1)) != -1) { /* @@ -5421,6 +5426,7 @@ buf[0] = '\0'; opts = buf; } + errno = saved_errno; break; case 1: if (issetugid() == 0 && (opts = >Release-Note: >Audit-Trail: >Unformatted: