From owner-freebsd-current@FreeBSD.ORG Tue Nov 25 13:41:16 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2C2C116A4CE for ; Tue, 25 Nov 2003 13:41:16 -0800 (PST) Received: from gw.celabo.org (gw.celabo.org [208.42.49.153]) by mx1.FreeBSD.org (Postfix) with ESMTP id A3AA043FE0 for ; Tue, 25 Nov 2003 13:41:13 -0800 (PST) (envelope-from nectar@celabo.org) Received: from madman.celabo.org (madman.celabo.org [10.0.1.111]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "madman.celabo.org", Issuer "celabo.org CA" (verified OK)) by gw.celabo.org (Postfix) with ESMTP id 36C8654883; Tue, 25 Nov 2003 15:41:13 -0600 (CST) Received: by madman.celabo.org (Postfix, from userid 1001) id D270E6D455; Tue, 25 Nov 2003 15:41:12 -0600 (CST) Date: Tue, 25 Nov 2003 15:41:12 -0600 From: "Jacques A. Vidrine" To: Enache Adrian Message-ID: <20031125214112.GC54467@madman.celabo.org> References: <20031123141408.GA1426@ratsnest.hole> <20031124174457.GB27782@madman.celabo.org> <20031125144624.GA1088@ratsnest.hole> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031125144624.GA1088@ratsnest.hole> X-Url: http://www.celabo.org/ User-Agent: Mutt/1.5.4i-ja.1 cc: current@freebsd.org Subject: Re: [PATCH] libc_r bug: successful close(2) sets errno to ENOTTY X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Nov 2003 21:41:16 -0000 On Tue, Nov 25, 2003 at 04:46:24PM +0200, Enache Adrian wrote: > On Mon, Nov 24, 2003 a.d., Jacques A. Vidrine wrote: > > The application is broken. You must only check errno if you get an > > error indication from the library call. > > Sorry, but I don't see your point. I know when to check for errno. > If you took the little illustrating program for a real life example of > the use of errno, that's unfortunate :-) > > The problem is that the emulated/wrapped close from libc_r does not > behave like the real one. libc_r is leaking some of its guts > (the tricks it's doing with O_NONBLOCK, etc) in the interface. > This is technically a bug. The fix was trivial. Hello Enache, My point was that this is not technically a bug. According to IEEE Std 1003.1-2001 aka the Single Unix Specification Version 3 (``SUSv3'') aka POSIX, an application must not examine and interpret `errno' unless the library gives an error indication. There are some functions--- strtol and family, sysconf, others--- that have unusual, errno-preserving behavior. These are described individually in the appropriate section of the standard. For these and only these, you can set errno to 0 and check it immediately after the function call to see whether an error has occurred. I believe that includes all functions described in ISO/IEC 9899:1999 (``C99''), as well as some described only in SUSv3. `close' is not a part of C99, nor is it attributed the `unusual', errno-preserving behavior in SUSv3. (By the way, this exact topic was discuss at some length by the the Austin Common Standards Revision Group this past summer.) Cheers, -- Jacques Vidrine NTT/Verio SME FreeBSD UNIX Heimdal nectar@celabo.org jvidrine@verio.net nectar@freebsd.org nectar@kth.se