zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Sebastian Gniazdowski <psprint3@fastmail.com>, zsh-workers@zsh.org
Subject: Re: Cannot write to zsystem flock's descriptor
Date: Wed, 1 Mar 2017 09:32:58 -0800	[thread overview]
Message-ID: <170301093258.ZM11760@torch.brasslantern.com> (raw)
In-Reply-To: <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.


      reply	other threads:[~2017-03-01 17:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-01 10:49 Sebastian Gniazdowski
2017-03-01 17:32 ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=170301093258.ZM11760@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=psprint3@fastmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).