From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 1507 invoked from network); 7 Jun 2020 17:01:07 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 7 Jun 2020 17:01:07 -0000 Received: (qmail 6004 invoked by alias); 7 Jun 2020 17:01:02 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 46020 Received: (qmail 20095 invoked by uid 1010); 7 Jun 2020 17:01:02 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-11.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25828. spamassassin: 3.4.4. Clear:RC:0(80.0.253.75):SA:0(-2.0/5.0):. Processed in 2.910888 secs); 07 Jun 2020 17:01:02 -0000 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _smtprelay.virginmedia.com designates 80.0.253.75 as permitted sender) X-Originating-IP: [86.16.88.158] X-Authenticated-User: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.3 cv=Mq3mFFSe c=1 sm=1 tr=0 a=MiHCjVqLJ44lE3bxSlffFQ==:117 a=MiHCjVqLJ44lE3bxSlffFQ==:17 a=IkcTkHD0fZMA:10 a=sbU-5AmOjyCQ2AqrrLMA:9 a=QEXdDO2ut3YA:10 Message-ID: <15816a8422ec6889dda0f62bf80b11a88163ea3b.camel@ntlworld.com> Subject: Re: Any way to allow clobbering empty files when noclobber is set? From: Peter Stephenson To: zsh-workers@zsh.org Date: Sun, 07 Jun 2020 18:00:21 +0100 In-Reply-To: <20200607115515.6624e240@tarpaulin.shahaf.local2> References: <89aed74d-db7b-47ad-b218-8158838049e9@www.fastmail.com> <94e73ebcf39d4d3f9c7ae257b1d75d16@CAMSVWEXC01.scsc.local> <20200605020748.635b9bb3@tarpaulin.shahaf.local2> <1941572212.466119.1591360860372@mail2.virginmedia.com> <13acd486e6457c1f708304026c3e1b59521ad328.camel@ntlworld.com> <20200607115515.6624e240@tarpaulin.shahaf.local2> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfFMGb3xltEFvqLzKEryp1KxxQp2D4dFn3h+L8xxb7i6ejut4rjlk+npE6c4XLSH9fZpoHAH8vwUNIPTHzXFa2WVEYqF1D71+EZOBhHR8R/U45ThBiYPz cUOO+LgRaI8QwSRVNh22O3zPvBMNJsokpTi9zefzPPb7lOxTK8hOERAp On Sun, 2020-06-07 at 11:55 +0000, Daniel Shahaf wrote: > My point here is really just the one I already made in 45976, and > wasn't answered there: can't we avoid the close()-then-open() sequence > that 45968 does? That one seems to be an _avoidable_ race condition, > unlike the above ones. I think what it boils down to here is either you test using fstat() the the file is empty, or you re-open using O_TRUNC, both of which ensure the file is empty at that point. Then at some later point, the file will be written to. Between the two it's there but empty, which is unavoidable. So my last change, closing and opening with O_TRUNC, doesn't really gain anything over leaving it open after checking the size with fstat(), I don't think, in which case the extra open() is redundant and best removed (and that puts us in the fortuitous position where we haven't actually added any system calls in adding CLOBBER_EMPTY). But I don't think taking it out actually removes a race. pws