zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Sebastian Gniazdowski <psprint2@fastmail.com>, zsh-workers@zsh.org
Subject: Re: Closing descriptors in forked (pipe) command
Date: Sat, 18 Feb 2017 21:02:00 -0800	[thread overview]
Message-ID: <170218210200.ZM27007@torch.brasslantern.com> (raw)
In-Reply-To: <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.


  reply	other threads:[~2017-02-19  5:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-18 12:45 Sebastian Gniazdowski
2017-02-19  5:02 ` Bart Schaefer [this message]
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=170218210200.ZM27007@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=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).