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 32345 invoked from network); 8 Jun 2020 03:28:24 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 8 Jun 2020 03:28:24 -0000 Received: (qmail 25663 invoked by alias); 8 Jun 2020 03:28:15 -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: 46023 Received: (qmail 21931 invoked by uid 1010); 8 Jun 2020 03:28:15 -0000 X-Qmail-Scanner-Diagnostics: from wout4-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25835. spamassassin: 3.4.4. Clear:RC:0(64.147.123.20):SA:0(-2.6/5.0):. Processed in 3.94165 secs); 08 Jun 2020 03:28:15 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudehtddgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfgjfhfogggtgfesthhqtddtredtjeenucfhrhhomhepffgrnhhi vghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvgeqne cuggftrfgrthhtvghrnhephfdtteefheevuedthedutdeifeegteettdejtdffheduieei jeelteetkeduteehnecukfhppeejledrudejiedrfeelrdeileenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegurghnihgvlhdrshhh rghhrghfrdhnrghmvg X-ME-Proxy: Date: Mon, 8 Jun 2020 03:27:30 +0000 From: Daniel Shahaf To: Peter Stephenson Cc: zsh-workers@zsh.org Subject: Re: Any way to allow clobbering empty files when noclobber is set? Message-ID: <20200608032730.614e197c@tarpaulin.shahaf.local2> In-Reply-To: <15816a8422ec6889dda0f62bf80b11a88163ea3b.camel@ntlworld.com> 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> <15816a8422ec6889dda0f62bf80b11a88163ea3b.camel@ntlworld.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Peter Stephenson wrote on Sun, 07 Jun 2020 18:00 +0100: > 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. =20 >=20 > 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. *nod* > 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. The race is: 1. zsh runs =C2=AB: > existing-empty-file=C2=BB. 2. zsh calls open(O_EXCL) which fails, then open() and fstat(), which both = succeeds. 3. Some other process writes data to the file. 4. zsh opens the file with O_TRUNC. 5. bin_true() returns, not having written anything to the file. 6. zsh closes the file. Step=C2=A0#4 will have deleted the other process's data. If we remove the close()/open() pair, the step=C2=A0#4 data will survive. It's an edge case, yes. Cheers, Daniel