Zsh Mailing List Archive
Messages sorted by:
Re: Closing descriptors in forked (pipe) command
- X-seq: zsh-workers 40577
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Sebastian Gniazdowski <psprint2@xxxxxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: Closing descriptors in forked (pipe) command
- Date: Sat, 18 Feb 2017 21:02:00 -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=3nLpMiKRGKOK+9+4hxCplK3tf3tI61MOxhpsAJpvgkg=; b=1au2IEEuh8VoQsndDkSW1mMXSHNW+arY6EcKZs6EzH2pAOU0fPGCoo6osyOQHI8mrT k4t7/IVZlkzHK25gKHRs9xyHeb1kBuyrXALMzb+gQtj5Lw8iKkEcxX5Gc1iyh3nlQwmO gyInxP6G7E8D2LHel6a4JrjIQ5xZFGvnuGZPOBv2i8fFc+IbjT6Gz8yXm5BuPvG8OzKe aDwuWt8lw4r2XmxV4HdswDdKMeKSKb4PWtV4nQ61akWf+8wdgYjyN5//WO8e96hdt86X rSUxx3uGBpiB7T+1mjgnO74YI0/6cMZS20ZCRGcPhP/92t7i7cjrE59KfSrQJZiAlQNO 4gBg==
- In-reply-to: <1487421943.63900.885130720.703DA037@webmail.messagingengine.com>
- List-help: <mailto:email@example.com>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:firstname.lastname@example.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <1487421943.63900.885130720.703DA037@webmail.messagingengine.com>
On Feb 18, 4:45am, Sebastian Gniazdowski wrote:
} in db/gdbm module, I do:
} addmodulefd(gdbm_fdesc(dbf), FDT_MODULE);
} The point is: forked process inherits database connection. GDBM cannot
} have multiple writers (open is in write mode).
That's not true -- "man gdbm" even mentions:
If the database was opened with the GDBM_NOLOCK flag, the user may
wish to perform their own file locking on the database file in order
to prevent multiple writers operating on the same file simultaneously.
} Maybe it would be good to solve this? FDT_FORKCLOSE or something, there
} is closeallelse(), for multiio, didn't go deeper in this.
In the general case a subshell should be inheriting all descriptors from
the parent, and it's up to the shell programmer not to do stupid things.
Consider the case where the parent shell wishes to ztie to the database,
fork off a subshell that will make use of the tied parameter, and then
go on to exec something else or otherwise exit, leaving the subshell to
manage the database.
You/we certainly may wish to document that it is dangerous to assume
that parent and subshell can both manipulate the tied parameter, but
it would be incorrect to automatically close the file descriptor in
either of them.
This is actually part of the reason why bin_ztie() uses GDBM_SYNC
when opening the database file.
Messages sorted by: