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 30462 invoked from network); 5 Jun 2020 02:00:35 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 5 Jun 2020 02:00:35 -0000 Received: (qmail 12749 invoked by alias); 5 Jun 2020 02:00:27 -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: 45976 Received: (qmail 26994 invoked by uid 1010); 5 Jun 2020 02:00:27 -0000 X-Qmail-Scanner-Diagnostics: from wout5-smtp.messagingengine.com 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(64.147.123.21):SA:0(-2.6/5.0):. Processed in 1.010849 secs); 05 Jun 2020 02:00:27 -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: gggruggvucftvghtrhhoucdtuddrgeduhedrudegvddghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfgjfhfogggtgfesthhqtddtredtjeenucfhrhhomhepffgrnhhi vghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvgeqne cuggftrfgrthhtvghrnhephfdtteefheevuedthedutdeifeegteettdejtdffheduieei jeelteetkeduteehnecukfhppeejledrudejiedrfeelrdeileenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegurghnihgvlhdrshhh rghhrghfrdhnrghmvg X-ME-Proxy: Date: Fri, 5 Jun 2020 01:59:48 +0000 From: Daniel Shahaf To: Bart Schaefer Cc: "zsh-workers@zsh.org" , Martin Tournoij Subject: Re: Any way to allow clobbering empty files when noclobber is set? Message-ID: <20200605015948.0c26ca38@tarpaulin.shahaf.local2> In-Reply-To: References: <89aed74d-db7b-47ad-b218-8158838049e9@www.fastmail.com> <94e73ebcf39d4d3f9c7ae257b1d75d16@CAMSVWEXC01.scsc.local> <99742213.429535.1591272937010@mail2.virginmedia.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 Bart Schaefer wrote on Thu, 04 Jun 2020 13:35 -0700: > On Thu, Jun 4, 2020 at 5:16 AM Peter Stephenson > wrote: > > > > One thing I missed is that we already open the file and run fstat to > > check if it's regular. We can simply check if it's empty at the > > same point =20 >=20 > Exactly where my earlier question came from. >=20 > > + if (isset(CLOBBEREMPTY) && buf.st_size =3D=3D 0) > > + { > > + close(fd); > > + return open(ufname, O_WRONLY | O_CREAT | O_TRUNC | O_NO= CTTY, > > + 0666); > > + } =20 >=20 > Considering the concurrent-openers situation that Roman mentioned, I'm > debating whether there is any benefit to doing: >=20 > int newfd =3D open(ufname, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY, 066= 6); > close(fd); > return newfd; >=20 > I have a vague sense that keeping the descriptor open until the new > file is created might prevent some races, but I can't recite an > example. This wouldn't prevent races, because the filename might be unlinked between the first and second open(2) calls. I think the right fix here is to simply change the body of the quoted if statement to =C2=ABreturn fd=C2=BB. What do we gain by re-opening the f= ile with the O_TRUNC flag set when we already know the file is zero-length? It seems to me we're just introducing a race condition for no reason.