]> git.ipfire.org Git - thirdparty/git.git/commit
fsmonitor: close inherited file descriptors and detach in daemon
authorPaul Tarjan <github@paulisageek.com>
Wed, 15 Apr 2026 13:27:34 +0000 (13:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Apr 2026 15:44:33 +0000 (08:44 -0700)
commit9266aaff0aba923eb6ef08a24d413ed7052818d7
tree3d341bace4125f6d0670de8fc4336db57f299ec4
parent50dc89cdfb6d8495853ceac4801c1cca9cd4ce38
fsmonitor: close inherited file descriptors and detach in daemon

When the fsmonitor daemon is spawned as a background process, it may
inherit file descriptors from its parent that it does not need.  In
particular, when the test harness or a CI system captures output through
pipes, the daemon can inherit duplicated pipe endpoints.  If the daemon
holds these open, the parent process never sees EOF and may appear to
hang.

Set close_fd_above_stderr on the child process at both daemon startup
paths: the explicit "fsmonitor--daemon start" command and the implicit
spawn triggered by fsmonitor-ipc when a client finds no running daemon.
Also suppress stdout and stderr on the implicit spawn path to prevent
the background daemon from writing to the client's terminal.

Additionally, call setsid() when the daemon starts with --detach to
create a new session and process group.  This prevents the daemon
from being part of the spawning shell's process group, which could
cause the shell's "wait" to block until the daemon exits.

Signed-off-by: Paul Tarjan <github@paulisageek.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsmonitor--daemon.c
fsmonitor-ipc.c