From: Sebastian Gniazdowski <psprint2@fastmail.com>
To: zsh-workers@zsh.org
Subject: Closing descriptors in forked (pipe) command
Date: Sat, 18 Feb 2017 04:45:43 -0800 [thread overview]
Message-ID: <1487421943.63900.885130720.703DA037@webmail.messagingengine.com> (raw)
Hello,
in db/gdbm module, I do:
addmodulefd(gdbm_fdesc(dbf), FDT_MODULE);
this should lead to problem, but it behaves the same as with
FDT_INTERNAL, i.e. following:
% ztie -d db/gdbm -f ~/db3 mybase2
% fun() { while read line; do echo $line; done }
% eval "print -rl -- \${(kv)mybase2[@]}" | fun
% echo $mybase2
The point is: forked process inherits database connection. GDBM cannot
have multiple writers (open is in write mode). Above outputs:
(Dbase accessed)
testkey
testdata
(Dbase accessed)
testkey
testdata
"(Dbase accessed)" is printf from code where $mybase2 turns out to be
empty for given key and database fetch is ordered. So it's visible that
there is fork because database is accessed twice – $mybase2 is still
empty at line "echo $mybase2". Good that GDBM handles change to
file-descriptor's file position pointer (AFAIK it's shared between FDs),
and reads the data again correctly. With write it also works, but
potentially the database might get corrupted silently:
% ztie -d db/gdbm -f ~/db3 mybase2
% fun() { while read line; do echo $line; done }
% eval "mybase2[漢]=字" | fun
(Dbase accessed)
% echo $mybase2[漢]
(Dbase accessed)
字
Maybe it would be good to solve this? FDT_FORKCLOSE or something, there
is closeallelse(), for multiio, didn't go deeper in this.
--
Sebastian Gniazdowski
psprint2@fastmail.com
next reply other threads:[~2017-02-18 12:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-18 12:45 Sebastian Gniazdowski [this message]
2017-02-19 5:02 ` Bart Schaefer
2017-02-19 8:04 ` Sebastian Gniazdowski
2017-02-19 10:51 ` [PATCH] " Sebastian Gniazdowski
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=1487421943.63900.885130720.703DA037@webmail.messagingengine.com \
--to=psprint2@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).