From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23821 invoked by alias); 10 Sep 2016 17:01:37 -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: 39268 Received: (qmail 29415 invoked from network); 10 Sep 2016 17:01:37 -0000 X-Qmail-Scanner-Diagnostics: from mail-pf0-f193.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.192.193):SA:0(0.0/5.0):. Processed in 1.486277 secs); 10 Sep 2016 17:01:37 -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=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at brasslantern.com does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=nuxzY+GsJ5MW9nk+qs7m9IbeW2S9daSMNzQsSj5Agaw=; b=P9jB+L0Qvzti0kra1CqXgNSO1Yq3O/h1c3UZRwTp5Ow8nNOrLTj0YmBDquAbMbwtvA zyx/pDSgUG8TwTUKU6CGMU//ADxD4Rq1z71NeyqoNsitlmZlTFOJ655exYu+UuPRs8OC yd09LRinayC7QwAxx/wKy+iTFBHsMohVmF1BBOrCF4e4mVSUQXohNWVjM8in2mKOvyMx l9ctqSz4W9gIVzGdwA8+NE/3PdxXKhG+tQjDTrBJI3F5vu4d3dDHQ23f5sV8pdDGK2UQ QuSPx1WjbYRZ3QTQZ/Bzupkg9M5Dxx0XBZ1zL6IqRgo0oNw/hpT1CSlha/3F7CbQtX4R iZLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=nuxzY+GsJ5MW9nk+qs7m9IbeW2S9daSMNzQsSj5Agaw=; b=ATqge78hqCqXVyBWwyO9gRPouuWp52FX+a/DwtaZgfgn5e8n6McItwo5sGXNeMaMIn NXDYIh8d0HLKFbh3tlryGDFKJ4219b5Hw2HcuZvQj3QeREdwB3pY9bLeNW5xmOh3/HMG pKnwzi1Z+D9z6N6WkmIrwgafa7ly6810x9fN8S7OMn1HO9eILmYu7dVESVobssR6npOL FxtgHF1bxfbsO2uiI93Hq0jH2OEP9or3OaTdxcbDMuqM1btmdC6SOQ4n+fFgvUNdvBX8 RQPyDMI/Pxslg24Dl9bbgzyQpc6x2qc6ANl/jJ761W1lL+vwxcac6p+TjDYhkibBL9zH GDNQ== X-Gm-Message-State: AE9vXwOQbBiJHS3aRMnBr52SBUpXF9tQZIu7x5u8HTlNa4jgAQIH6JDgQi8yoJP2IdMq+g== X-Received: by 10.98.66.74 with SMTP id p71mr17207057pfa.143.1473526878160; Sat, 10 Sep 2016 10:01:18 -0700 (PDT) From: Bart Schaefer Message-Id: <160910100122.ZM23143@torch.brasslantern.com> Date: Sat, 10 Sep 2016 10:01:22 -0700 In-Reply-To: Comments: In reply to Sebastian Gniazdowski "[PATCH] Allow zsystem flock to query without second-lasting timeout" (Sep 10, 5:49pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh hackers list Subject: Re: [PATCH] Allow zsystem flock to query without second-lasting timeout MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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)