git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-daemon problem

From
Junio C Hamano <junkio@cox.net>
Date
Jul 13, 2006, 05:44 UTC
Message-ID
<7vveq2ukho.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<E1G0kNV-0006LK-QW@moooo.ath.cx>
Matthias Lederhofer <matled@gmx.net> writes:
Show 15 quoted lines
> Junio C Hamano <junkio@cox.net> wrote:
>> This breaks the newer clients that knows how to do side-band
>> doesn't it?
> Probably, this patch is just to give a starting point where the
> problem could be.
>
>> Would this replacement patch help?
> [use write instead of safe_write]
>
> This seems to fix it.  Perhaps it should be xwrite instead of write.
>
>> 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?
Previous: Matthias LederhoferNext: Matthias Lederhofer
Message 6 of 23 in “git-daemon problem”
  1. Matthias LederhoferJul 11, 2006
  2. Junio C HamanoJul 11, 2006
  3. Junio C HamanoJul 11, 2006
  4. Junio C HamanoJul 12, 2006
  5. Matthias LederhoferJul 12, 2006
  6. Junio C HamanoJul 13, 2006
  7. Matthias LederhoferJul 13, 2006
  8. Andre NollJul 13, 2006
  9. Matthias LederhoferJul 13, 2006
  10. 1/5 daemon: use a custom die routine with syslogMatthias Lederhofer, Jul 13, 2006
  11. 2/5 daemon: if one of the standard fds is missing open it to /dev/nullMatthias Lederhofer, Jul 13, 2006
  12. Edgar ToernigJul 13, 2006
  13. Matthias LederhoferJul 13, 2006
  14. Uwe ZeisbergerJul 13, 2006
  15. Morten WelinderJul 13, 2006
  16. Matthias LederhoferJul 13, 2006
  17. 1/5 daemon: if one of the standard fds is missing open it to /dev/nullMatthias Lederhofer, Jul 13, 2006
  18. 4/5 daemon: new option --pid-file=<path> to store the pidMatthias Lederhofer, Jul 13, 2006
  19. 5/5 daemon: new option --detach to run git-daemon in backgroundMatthias Lederhofer, Jul 13, 2006
  20. Edgar ToernigJul 13, 2006
  21. Matthias LederhoferJul 13, 2006
  22. 3/5 upload-pack: ignore write errors to stderrMatthias Lederhofer, Jul 13, 2006
  23. daemon: documentation for --reuseaddr, --detach and --pid-fileMatthias Lederhofer, Jul 14, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.