From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24024 invoked by alias); 10 Sep 2016 23:40:46 -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: X-Seq: 39269 Received: (qmail 11881 invoked from network); 10 Sep 2016 23:40:46 -0000 X-Qmail-Scanner-Diagnostics: from mail-qk0-f170.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.220.170):SA:0(0.0/5.0):. Processed in 1.19299 secs); 10 Sep 2016 23:40:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM,SPF_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: sgniazdowski@gmail.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.220.170 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3PK967qIm9irLpSTE37GKTYvCx+hrkQuLtxntQFXRuM=; b=kuLalJa8Rco8lHRAQE1dowYLEBmVzopgzNIDbBJR5gR5kscgnKXtPJwNxlYPtnMjRT apT/J4io2cLraMIOHAS1TuYJu2zX8HG33se/RhJQW8aO4A6/bmWndZ91mvlVn8LaMg0W cKxCs8dVHjIR7Lh6te9dx6lf8BomhelfVwy4Lu8DZ/vVeoDqpfciorzSFun4GxotpL9+ mkvBAeuxH9fmuQ8EI20BBqNjE5E0cnaI9cnL8qZaJ7qHhnrnR60NQDb4Sg2Fxz18k4GX 4+WI7uXlrUqTE7bWgmLSHQpObXce5qxpncWvufpfAllFmOmQrfCe0hvlf5y1WjrQA4Pl VIlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3PK967qIm9irLpSTE37GKTYvCx+hrkQuLtxntQFXRuM=; b=ID5BjIQ9XVTOXpINOEHf2beedO2wQulderUCD3bPvFniWXHFJaB/tgWBKjTiz5s/4V 6Wg/lh1lmOgSYZJL/+refnMOBBA9DjzQs+xD6B+TrtItwrnp81aOLkhzqOaACWNpV5S8 6hLLq/k48ah0KsYgvMoPx7+uQcpS2PcHaMxkRtUYK3+NyHxmrIgWffVSD9vW2n4sMoF+ ehXHqw6nkw/lC7Oe9sedhRQofZUl+DZrW0bNzngUpSiw3SZhe1/H8iYKQVQPBGURny0V NyEN8P+WvmjjNiBAOIEAdABiPmM+NJrjiIR/8rXvFfsdcGtKvJBZhKgovkjeeUb+2nf8 FMjA== X-Gm-Message-State: AE9vXwMCR0YtB7DAJyaQKv3CNMe3KZVuIbamAlEfn2EVcSLqifcXV+hawD3hsh8hsp521eBmjtpU3bMeMWIDNw== X-Received: by 10.55.209.202 with SMTP id o71mr12214592qkl.54.1473546788604; Sat, 10 Sep 2016 15:33:08 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <160910100122.ZM23143@torch.brasslantern.com> References: <160910100122.ZM23143@torch.brasslantern.com> From: Sebastian Gniazdowski Date: Sun, 11 Sep 2016 00:32:48 +0200 Message-ID: Subject: Re: [PATCH] Allow zsystem flock to query without second-lasting timeout To: Bart Schaefer Cc: Zsh hackers list Content-Type: text/plain; charset=UTF-8 Really cool, thanks, I will use this via is-at-least, now I've included cropped-down version of util-linux/flock in my plugin, it amazingly compiles on OS X (so probably also FreeBSD), and of course Linux Best regards, Sebastian Gniazdowski On 10 September 2016 at 19:01, Bart Schaefer wrote: > On Sep 10, 5:49pm, Sebastian Gniazdowski wrote: > } > } attached patch is dumb, and allows to use negative timeout, which > } results in a quick (non-waiting) single fcntl() call. > > I think a better approach would be to allow a zero timeout. (Why was > there already a cast of time_t to time_t in the time(NULL) expression?) > > Hopefully no one is already using the undocumented behavior that > "zsystem flock -t 0 ..." nevertheless waited forever. > > > diff --git a/Src/Modules/system.c b/Src/Modules/system.c > index 1ee61c0..afaec26 100644 > --- a/Src/Modules/system.c > +++ b/Src/Modules/system.c > @@ -521,7 +521,7 @@ static int > bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) > { > int cloexec = 1, unlock = 0, readlock = 0; > - time_t timeout = 0; > + zlong timeout = -1; > char *fdvar = NULL; > #ifdef HAVE_FCNTL_H > struct flock lck; > @@ -573,7 +573,7 @@ bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) > } else { > optarg = *args++; > } > - timeout = (time_t)mathevali(optarg); > + timeout = mathevali(optarg); > break; > > case 'u': > @@ -650,7 +650,7 @@ bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) > sleep(1); > } > } else { > - while (fcntl(flock_fd, F_SETLKW, &lck) < 0) { > + while (fcntl(flock_fd, timeout == 0 ? F_SETLK : F_SETLKW, &lck) < 0) { > if (errflag) > return 1; > if (errno == EINTR)