Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Cannot write to zsystem flock's descriptor
- X-seq: zsh-workers 40687
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Sebastian Gniazdowski <psprint3@xxxxxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: Cannot write to zsystem flock's descriptor
- Date: Wed, 1 Mar 2017 09:32:58 -0800
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=brasslantern-com.20150623.gappssmtp.com
- 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=yttmDjnBYIZEcdP4Qc/R/AxMqOgJIy+ES1HrVG7/clA=; b=mobQ69OQjzAkvhOUY0hPNQTi9MLgW+o9bkPDgbjwT9sHl/HASZMDSL13i+Uq5emhDP RxqRrmNRSQOZOXdAuVHfDFVwx+0TDPAKO51YEhZY7ArkbmcRp2AV8HpMkB5nrQw1TPUr ihBMhb4KzGZi2aR0K64tFruaM3H2R72T1OLnPQ1RsWyZQ5onMTSDMu0VUy1k2RU5VdUK KDfvLixlp6uyA1u77SgFJlkoWjIrzXXMgCh3VxuWppuKWoOvLFzPTXAq7Wq1pq4Y8akH Sd842jwMmuoVI71JoK0/HnWdZV46NQiw/gTVBYbfnoNQnOp3RQ05fwpbESTB+uuorXQ0 dp5Q==
- In-reply-to: <1488365385.3896802.896627648.08162014@webmail.messagingengine.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: <1488365385.3896802.896627648.08162014@webmail.messagingengine.com>
On Mar 1, 2:49am, Sebastian Gniazdowski wrote:
}
} # echo "test" > file
} # zsystem flock -t 0 -f MY_FD "file"; echo $?
} 0
} # echo a>&${MY_FD}
} zsh: 11: bad file descriptor
This is actually internal to zsh and has nothing to do with the state
of the descriptor itself. See addlockfd() in utils.c and lines 3524
to 3538 (approximately) in exec.c where the redirection is handled.
When you do >&${MY_FD} that implies duplicating the descriptor to
FD 1 of the "echo" job and then closing that descriptor when echo
has finished. Doing so with the descriptor that is being held for
flock could cause the lock to be prematurely released, so when the
table of allocated descriptors is scanned for those that are valid
as redirection targets, the FTD_FLOCK descriptors are skipped.
I don't recall whether this is a portability issue -- e.g., it could
safely be done on linux as the util-linux flock executable seems to
imply, but perhaps it can't be done elsewhere.
You can always open a different descriptor on the same file, or first
open a descriptor on the file and then flock. Locking with flock is
advisory only -- all programs accessing the file must agree to try
flock first -- so there's no restriction on other access before or
after flock is in place.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author