Re: git-daemon problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Junio C Hamano <junkio@xxxxxxx> wrote:
> Matthias Lederhofer <matled@xxxxxxx> writes:
> > Junio C Hamano <junkio@xxxxxxx> wrote:
> >> 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?
> > daemon startup is probably not the right place because as long as the
> > terminal is open this will be fine.
> 
> Hmph.  In the part of my message you did not quote:
> 
> 	$ git-daemon 0<&- 1>&- 2>&- --export-all /pub/git
> 
> leaves listening sockets at fd 0/1 without any fd 2, and
> 
> 	$ git-daemon 2>&- --export-all /pub/git
> 
> allocates listening socket at FD 2 (because FD 0 and FD 1 are
> occupied).
> 
> 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.  So in the latter case, my tentative
> patch would write error message to the listening socket -- ugh.
> 
> And as you say, fd 2 might be connected to the terminal and
> healthy when you start the daemon, but later you can close the
> terminal, so there is no sane place for us to try anything
> sensible.
> 
> The only "right" solution I could think of is to properly
> daemonize git-daemon when not running under --inetd mode.  Close
> and open /dev/null the low three fds, and dissociate the process
> from the controlling terminal (did I forget anything else --
> perhaps chdir("/") at the top?).  And we keep the current
> behaviour of assuming the sane set of low three fds when a new
> option --debug is given to help people look at its stderr.  The
> tentative patch to upload-pack would become moot at that point.
> 
> Hmm?

Now I see what you mean.  Checking the fds at daemon startup should
work too (using xwrite/write instead of safe_write).

Is daemon(3) portable?  Otherwise it should be:
fork(); setsid(); chdir("/"); open("/dev/null", O_RDWR, 0); dup2(..);
(looking at the daemon(3) implementations of glibc and freebsd libc)
The freebsd implementation of daemon(3) ignores SIGHUP for fork() and
setsid() with the comment "A SIGHUP may be thrown when the parent
exits below."

With the option to run in background (or the other way around -- not
to run in background) should also come an option to write a pid file.
-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]