Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Allow zsystem flock to query without second-lasting timeout
- X-seq: zsh-workers 39269
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: [PATCH] Allow zsystem flock to query without second-lasting timeout
- Date: Sun, 11 Sep 2016 00:32:48 +0200
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- 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==
- In-reply-to: <160910100122.ZM23143@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVDYBYx99+nUSS1nMuimRUtqhi8GGhUDawUn6BOg2M4c_g@mail.gmail.com> <160910100122.ZM23143@torch.brasslantern.com>
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 <schaefer@xxxxxxxxxxxxxxxx> 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)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author