From owner-svn-src-head@FreeBSD.ORG Sat Nov 1 11:32:16 2008 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 87D4E1065670; Sat, 1 Nov 2008 11:32:16 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail09.syd.optusnet.com.au (mail09.syd.optusnet.com.au [211.29.132.190]) by mx1.freebsd.org (Postfix) with ESMTP id 267238FC1A; Sat, 1 Nov 2008 11:32:15 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c122-106-151-199.carlnfd1.nsw.optusnet.com.au (c122-106-151-199.carlnfd1.nsw.optusnet.com.au [122.106.151.199]) by mail09.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id mA1BWCjJ009469 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 1 Nov 2008 22:32:14 +1100 Date: Sat, 1 Nov 2008 22:32:12 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Robert Watson In-Reply-To: <200810311514.m9VFEfi9083785@svn.freebsd.org> Message-ID: <20081101220954.B12551@delplex.bde.org> References: <200810311514.m9VFEfi9083785@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r184511 - head/lib/libc/gen X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Nov 2008 11:32:16 -0000 On Fri, 31 Oct 2008, Robert Watson wrote: > Log: > In example use of err(3) and errx(3), use sysexits(3) constants. Use of sysexits is a style bug here too (see a reply to the corresponding change in style.9 for more details). > Modified: head/lib/libc/gen/err.3 > ============================================================================== > --- head/lib/libc/gen/err.3 Fri Oct 31 15:11:01 2008 (r184510) > +++ head/lib/libc/gen/err.3 Fri Oct 31 15:14:40 2008 (r184511) > @@ -178,15 +178,16 @@ or a null pointer > Display the current errno information string and exit: > .Bd -literal -offset indent > if ((p = malloc(size)) == NULL) > - err(1, NULL); > + err(EX_OSERR, NULL); > if ((fd = open(file_name, O_RDONLY, 0)) == -1) > - err(1, "%s", file_name); > + err(EX_NOINPUT, "%s", file_name); These have other style bugs -- a null or incomplete error message makes a sysexits error code almost useful. Normal for malloc failure is errx(1, "malloc failed"). This intentionally uses errx() instead of err() since the usual error ENOMEM for malloc() failure is considered useless, and/or the code is supposed to be portable to systems where malloc() is not guaranteed to set errno on failure. FreeBSD's actually malloc() claims to always set errno to ENOMEM on error. It seems to actually do this. This involves clobbering any possibly-more useful different errno set by mmap() etc. after preserving the original errno in a nonstandard place. Apart from this, with malloc() being even more in userland and with possibly more complicated failure modes, the printing error code might be more useful. (Except of couse malloc9) neverl fails :-), and when it does the MALLOC_OPTIONS="A" mistake makes it abort.) Also, with malloc() more in userland, EX_OSERR for malloc failure is wronger than before. Normal for open failure is err(1, "cannot open %s", file_name);. Bruce