git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Eric Wong <e@80x24.org>
Cc: larsxschneider@gmail.com, git@vger.kernel.org, gitster@pobox.com,
	tboegi@web.de
Subject: Re: [PATCH v1 1/2] sha1_file: open window into packfiles with CLOEXEC
Date: Tue, 6 Sep 2016 13:38:23 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1609061333030.129229@virtualbox> (raw)
In-Reply-To: <20160905222715.GA30031@starla>

Hi Eric & Lars,

On Mon, 5 Sep 2016, Eric Wong wrote:

> larsxschneider@gmail.com wrote:
> > All processes that the Git main process spawns inherit the open file
> > descriptors of the main process. These leaked file descriptors can
> > cause problems.
> 
> 
> > -int git_open_noatime(const char *name)
> > +int git_open_noatime_cloexec(const char *name)
> >  {
> > -	static int sha1_file_open_flag = O_NOATIME;
> > +	static int sha1_file_open_flag = O_NOATIME | O_CLOEXEC;
> >  
> >  	for (;;) {
> >  		int fd;
> 
> If there's real problems being caused by lack of cloexec
> today, I think the F_SETFD fallback I proposed in
> https://public-inbox.org/git/20160818173555.GA29253@starla/
> will be necessary.

Yes, it is good to have that patch available to go if we need it. I do not
think that we will need it, though, as the biggest problems that are
solved through the CLOEXEC flag are ones caused on Windows, when files
cannot be deleted or renamed because there are still (uselessly) open
handles referencing them.

> I question the need for the "_cloexec" suffixing in the
> function name since the old function is going away entirely.

Me, too. While it is correct, it makes things harder to read, so it may
even cause more harm than it does good.

> I prefer all FD-creating functions set cloexec by default
> for FD > 2 to avoid inadvertantly leaking FDs.  So we
> ought to use pipe2, accept4, socket(..., SOCK_CLOEXEC), etc...
> and fallback to the racy+slower F_SETFD when not available.

In the original Pull Request where the change was contributed to Git for
Windows, this was tested (actually, the code did not see whether fd > 2,
but simply assumed that all newly opened file descriptors would be > 2
anyway), and it failed:

https://github.com/git-for-windows/git/pull/755#issuecomment-220247972

So it appears that we would have to exclude at least the code path to `git
upload-pack` from that magic.

Ciao,
Dscho

  parent reply	other threads:[~2016-09-06 11:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-05 21:11 [PATCH v1 0/2] Use CLOEXEC to avoid fd leaks larsxschneider
2016-09-05 21:11 ` [PATCH v1 1/2] sha1_file: open window into packfiles with CLOEXEC larsxschneider
2016-09-05 22:27   ` Eric Wong
2016-09-06  9:36     ` Jakub Narębski
2016-09-06 11:38     ` Johannes Schindelin [this message]
2016-09-07 13:20       ` Lars Schneider
2016-09-07 18:17         ` Eric Wong
2016-09-05 21:11 ` [PATCH v1 2/2] read-cache: make sure file handles are not inherited by child processes larsxschneider
2016-09-06 11:41   ` Johannes Schindelin
2016-09-06 21:06   ` Eric Wong
2016-09-07 13:39     ` Lars Schneider
2016-09-07 18:10       ` Eric Wong
2016-09-07 18:23         ` Junio C Hamano
2016-09-08  5:57           ` Lars Schneider
2016-09-08 17:37             ` Junio C Hamano

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=alpine.DEB.2.20.1609061333030.129229@virtualbox \
    --to=johannes.schindelin@gmx.de \
    --cc=e@80x24.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=larsxschneider@gmail.com \
    --cc=tboegi@web.de \
    /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.
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).