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 3412 invoked from network); 7 Jun 2020 17:21:29 -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:21:29 -0000 Received: (qmail 13750 invoked by alias); 7 Jun 2020 17:21:23 -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: 46021 Received: (qmail 7211 invoked by uid 1010); 7 Jun 2020 17:21:23 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot1-f42.google.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(209.85.210.42):SA:0(-1.9/5.0):. Processed in 1.189986 secs); 07 Jun 2020 17:21:23 -0000 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.210.42 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=NWDTX0PlbV5yezkiHTp+tnGS5Fz4wahksvBQJk4EWYI=; b=JukiYHfvFx4gMsJRvwhYEjQnqkb6KfilVqOpa9Ikb6Kb4qE7bWCufGQl1jN3jHEM/b izeoO+P96tItvHhwwi5Q6UPpVK4jmEH+i2zY2oPJWQoKYlJKyBGpACJgiVhcLmmuzf7C f/Spx4zqNZ8QzjyZs3t2ckjnj8KynX3PDAJBhMyI5xjRE8XHHnwpZ7rYt+v4jrpaT2Ri frdeTbE9OvUaTXkYxajJjWF4xV1p+Ajcz9NC596SKtvVgisZFO+/58+Zla/L6Hkr5+Pl SwuZqHt0Da6kYj/TXgpc3PKtJRehbruRfBDL9gqPDpbUvSCEUMjYliy10UEzxECv5vm8 NStA== X-Gm-Message-State: AOAM530QnS5EcK9ljNQ1Ql7M+Wd6XV730XDTUoY7/UWGBslaCDtXp19z DN+l0yl9spYyMjUC7trpD3P001gUNjFDApQIxZWGMQ== X-Google-Smtp-Source: ABdhPJw93PYAe5OnMHPb037PiEBXA+KE2eNEb7Qk1+DexIcqdmRW7n03G9krPRCX0QX8ampjVEwivcu2Jtc0CNXua5s= X-Received: by 2002:a9d:6349:: with SMTP id y9mr15727477otk.260.1591550448709; Sun, 07 Jun 2020 10:20:48 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <20200607115515.6624e240@tarpaulin.shahaf.local2> From: Bart Schaefer Date: Sun, 7 Jun 2020 10:20:37 -0700 Message-ID: Subject: Re: Any way to allow clobbering empty files when noclobber is set? To: Daniel Shahaf Cc: Peter Stephenson , "zsh-workers@zsh.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Jun 7, 2020 at 4:55 AM Daniel Shahaf wrote= : > > In the clobbering open, we use O_CREAT|O_TRUNC, which means: if it > doesn't exist, create it; if it already exists, truncate it. If some > other process calls open() on the same file immediately after our > open() [or subsequent write()] call returns, there's nothing we can do > about that. Also if another process already had the existing file open, whatever it was doing will be lost. (Aside: If it's an NFS file, and the other process continues writing, this often results in a block of NUL bytes where the NFS server fills in between the two write positions.) > As to CLOBBER_EMPTY, the situation is similar. We can call open() with > O_CREAT but neither O_EXCL nor O_TRUNC and then fstat() the resulting > file. The same race conditions as in the previous paragraphs exist > here too =E2=80=94 for example, someone could open() and write() to the f= ile > after we fstat() it =E2=80=94 but we neither can nor need to do any bette= r > about races in this case than in the others. This in fact avoids (or at least does a better job of avoiding) the problem with two different write positions if some other process has already opened the file for write.