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 17074 invoked from network); 6 Jun 2020 01:42:28 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 6 Jun 2020 01:42:28 -0000 Received: (qmail 27906 invoked by alias); 6 Jun 2020 01:42:20 -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: 45992 Received: (qmail 29999 invoked by uid 1010); 6 Jun 2020 01:42:20 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot1-f65.google.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(209.85.210.65):SA:0(-1.9/5.0):. Processed in 0.740872 secs); 06 Jun 2020 01:42:20 -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.65 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; bh=MO8fG+UD/VLxVEB7pF7ATIz/88Bhp55KLmCyeCm/X0o=; b=R5eJS/umwTmwPXZQaNTReeX/aHbIEle4PHGau/bvgy3vJnrKI8C6OELE6hrMDnfzGk 8TQW1qo9FLKsRrd/89ELRBGa2GfUXBdWS816OezyYIzh3dd9Amngl+Ea+CinL4A6/Xno LrLp8HOivebW3TvxYIYTownBTHogz47Jh8KtgA0myb9bWaLnh0pElEvESKzx/8IIfDdv bRlPPI+nwIRg9s8/cRhOmBTTU5k9EtrFoz0YGSHq0bUye+epG73winAmC/exrAQqsyuB 70cAoF+khG1z319Tn2EWLU3NJaIlz/lt2qaCtlbObHUIqtEflQf0zaqDBtNhaFquQHuW Zuxw== X-Gm-Message-State: AOAM532Jsw75NigD5LBqRuEgcrD0ySi7BB658IYiXB6k5e5dFF5ruJyP y4nbsfxavjaIlP++/HH9yfT8LmukL4og/JX3UP/Av+q96KLLDA== X-Google-Smtp-Source: ABdhPJzVwunod8XW5BAF25Ah3br+MQ/rmlWhtqlSzwLxfUrNHB2ibqCThu4uwCUE6vb87h0Hf45TMBH2Yk56AAIRegc= X-Received: by 2002:a9d:6c4e:: with SMTP id g14mr6557940otq.229.1591407706715; Fri, 05 Jun 2020 18:41:46 -0700 (PDT) MIME-Version: 1.0 References: <89aed74d-db7b-47ad-b218-8158838049e9@www.fastmail.com> <94e73ebcf39d4d3f9c7ae257b1d75d16@CAMSVWEXC01.scsc.local> <20200605020748.635b9bb3@tarpaulin.shahaf.local2> In-Reply-To: From: Bart Schaefer Date: Fri, 5 Jun 2020 18:41:35 -0700 Message-ID: Subject: Re: Any way to allow clobbering empty files when noclobber is set? To: "zsh-workers@zsh.org" Cc: Martin Tournoij Content-Type: text/plain; charset="UTF-8" On Thu, Jun 4, 2020 at 9:39 PM Roman Perepelitsa wrote: > > write() print -rn -- $1 > rm -f foo > write hello >foo & > write bye >foo & > wait > > With regular no_clobber it has the following guarantees: > > 1. `write` is executed exactly once > 2. once `wait` completes, `foo` contains either "hello" or "bye" I don't think that's the intended typical usage of noclobber. It's not set by default, and it can't have any effect outside the local shell. It's meant to keep you from making silly mistakes when interacting with the interpreter, not as a concurrent programming tool. Nevertheless: > Is there a way to provide these guarantees with clobber_empty? With clobber, you have #2, but not #1, so I think we should focus on whether clobber_empty can guarantee #2. If you want #1, there are other ways (but I suspect it arises from the implementation of #2 even so). I think the answer is that #2 can be guaranteed if and only if fcntl()-based locking can be applied, or some equivalent kernel mechanism such that no more than closing of the (last dup of the) descriptor is necessary to release the lock. The steps would have to be: 1. Open the file for write without truncate. 2. Attempt lock, non-blocking, and immediately close/fail if not locked. 3. Check for zero size, and immediately unlock/close/fail when nonzero. 4. Return the locked descriptor.