From owner-freebsd-hackers@freebsd.org Fri Dec 29 18:28:36 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 94644EA99CA for ; Fri, 29 Dec 2017 18:28:36 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from outbound1a.eu.mailhop.org (outbound1a.eu.mailhop.org [52.58.109.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 32B3C74DE7 for ; Fri, 29 Dec 2017 18:28:35 +0000 (UTC) (envelope-from ian@freebsd.org) X-MHO-User: ea084504-ecc5-11e7-8dac-d32f5c2d02ef X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Originating-IP: 73.78.92.27 X-Mail-Handler: DuoCircle Outbound SMTP Received: from ilsoft.org (unknown [73.78.92.27]) by outbound1.eu.mailhop.org (Halon) with ESMTPSA id ea084504-ecc5-11e7-8dac-d32f5c2d02ef; Fri, 29 Dec 2017 18:27:25 +0000 (UTC) Received: from rev (rev [172.22.42.240]) by ilsoft.org (8.15.2/8.15.2) with ESMTP id vBTIRLx8003559; Fri, 29 Dec 2017 11:27:21 -0700 (MST) (envelope-from ian@freebsd.org) Message-ID: <1514572041.12000.7.camel@freebsd.org> Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? From: Ian Lepore To: Yuri , Freebsd hackers list Date: Fri, 29 Dec 2017 11:27:21 -0700 In-Reply-To: <24acbd94-c52f-e71a-8a96-d608a10963c6@rawbw.com> References: <24acbd94-c52f-e71a-8a96-d608a10963c6@rawbw.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.1 FreeBSD GNOME Team Port Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Dec 2017 18:28:36 -0000 On Fri, 2017-12-29 at 10:19 -0800, Yuri wrote: > Some base utilities sometimes close files that they open for their  > purposes without checking the error code of close(2). > > Is this considered to be ok, because it's just a close call and we > are  > done with that file descriptor, or is it considered to be more  > appropriate to check close's error code? > > Maybe there is some policy that covers this? > > IMO, every system call's return value should be checked, just in > case. > > > Yuri > There's really no point in checking on a close from a file opened only for reading.  You can argue it should be checked on a file open for writing, but often isn't because you're then confronted with the question "what should/can I do if there is an error?"  If you report the error and exit, then what about other files that were open at the time?  They're going to be closed by the kernel as part of process cleanup, with no error checking or reporting. Also, with the async nature of filesystems, IO errors can still happen after the close, unless fsync() was used.  So if you're going to miss most of the errors because of that, why bother to check at all? -- Ian