git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Matthias Lederhofer <matled@gmx.net>
Cc: git@vger.kernel.org
Subject: Re: git-daemon problem
Date: Tue, 11 Jul 2006 21:42:33 -0700	[thread overview]
Message-ID: <7vlkqz1lja.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <E1G0QeX-0003hG-0I@moooo.ath.cx> (Matthias Lederhofer's message of "Wed, 12 Jul 2006 00:24:24 +0200")

Matthias Lederhofer <matled@gmx.net> writes:

> A few weeks ago upgrading from 1.3.x to 1.4.1 I had a problem with
> git-daemon.  I started git-daemon on a terminal but did not redirect
> stdin/stdout/stderr to /dev/null (actually using daemon(8) on freebsd
> without -f but just disowning the process and closing the terminal
> works fine too, nothing freebsd/daemon(8) specific).  After closing
> the terminal I was not able to use the git-daemon anymore with some
> versions of the git. So now I took some time and tried to find what
> was the reason for that.

HMMMMMMMMM.

I did this silly experiment.  Close, instead of connecting them
to /dev/null, the low 3 file descriptors:

$ git-daemon 0<&- 1>&- 2>&- --export-all /pub/git &
$ lsof -p $! | sed -n -e '/ FD /p' -e '/[0-9]u/p'
COMMAND     PID  USER   FD   TYPE  DEVICE    SIZE    NODE NAME
git-daemo 13921 junio    0u  IPv6 1973673             TCP *:9419 (LISTEN)
git-daemo 13921 junio    1u  IPv4 1973674             TCP *:9419 (LISTEN)

It gets worse.  This is what happens when you close only fd #2.

$ git-daemon 2>&- --export-all /pub/git &
$ lsof -p $! | sed -n -e '/ FD /p' -e '/[0-9]u/p'
COMMAND     PID  USER   FD   TYPE  DEVICE    SIZE    NODE NAME
git-daemo 13961 junio    0u   CHR   136,7               9 /dev/pts/7
git-daemo 13961 junio    1u   CHR   136,7               9 /dev/pts/7
git-daemo 13961 junio    2u  IPv6 1975187             TCP *:9419 (LISTEN)
git-daemo 13961 junio    3u  IPv4 1975188             TCP *:9419 (LISTEN)

Now, after we do accept(), we spawn a subprocess in handle(),
and in the child process dup2() the fd connected to the peer to
fd 0 and 1 of the child process -- and we do not do anything to
fd 2 of the child process.

If you do not close any of the low 3 file descriptors, fd 2 of
the child process is connected to whatever error stream of
daemon is, so you would not see this problem, but this certainly
is bad.

Maybe we should check if fd 2 is sane at daemon startup, and
otherwise open /dev/null for writing and dup2 it to fd 2?

Currently, under --inetd mode we have freopen of stderr, but
that does not help this issue.  It would make die() and error()
in daemon itself behave sanely but when you start the daemon
with the low file descriptors closed, fileno(stderr) may be
different from 2.

  parent reply	other threads:[~2006-07-12  4:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-11 22:24 git-daemon problem Matthias Lederhofer
2006-07-11 23:04 ` Junio C Hamano
2006-07-11 23:32 ` Junio C Hamano
2006-07-12  4:42 ` Junio C Hamano [this message]
2006-07-12 19:28   ` Matthias Lederhofer
2006-07-13  5:44     ` Junio C Hamano
2006-07-13  7:42       ` Matthias Lederhofer
2006-07-13 11:42       ` Andre Noll
2006-07-13 11:51 ` Matthias Lederhofer
2006-07-13 10:02   ` [PATCH 1/5] daemon: use a custom die routine with syslog Matthias Lederhofer
2006-07-13 10:10   ` [PATCH 2/5] daemon: if one of the standard fds is missing open it to /dev/null Matthias Lederhofer
2006-07-13 13:27     ` Edgar Toernig
2006-07-13 14:04       ` Matthias Lederhofer
2006-07-13 14:36         ` Uwe Zeisberger
2006-07-13 15:37     ` Morten Welinder
2006-07-13 16:03       ` Matthias Lederhofer
2006-07-13 16:32     ` [PATCH 2.1/5] " Matthias Lederhofer
2006-07-13 10:18   ` [PATCH 4/5] daemon: new option --pid-file=<path> to store the pid Matthias Lederhofer
2006-07-13 10:32   ` [PATCH 5/5] daemon: new option --detach to run git-daemon in background Matthias Lederhofer
2006-07-13 13:37     ` Edgar Toernig
2006-07-13 16:47       ` [PATCH 5.1/5] " Matthias Lederhofer
2006-07-13 11:07   ` [PATCH 3/5] upload-pack: ignore write errors to stderr Matthias Lederhofer
2006-07-14 15:53   ` [PATCH] daemon: documentation for --reuseaddr, --detach and --pid-file Matthias Lederhofer

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=7vlkqz1lja.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    --cc=matled@gmx.net \
    /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).