return err;
}
-static int try_to_run_foreground_daemon(int detach_console MAYBE_UNUSED)
+static int try_to_run_foreground_daemon(int detach_console)
{
/*
* Technically, we don't need to probe for an existing daemon
fflush(stderr);
}
+ if (detach_console) {
#ifdef GIT_WINDOWS_NATIVE
- if (detach_console)
FreeConsole();
+#else
+ /*
+ * Create a new session so that the daemon is detached
+ * from the parent's process group. This prevents
+ * shells with job control (e.g. bash with "set -m")
+ * from waiting on the daemon when they wait for a
+ * foreground command that implicitly spawned it.
+ */
+ if (setsid() == -1)
+ warning_errno(_("setsid failed"));
#endif
+ }
return !!fsmonitor_run_daemon();
}
cp.no_stdin = 1;
cp.no_stdout = 1;
cp.no_stderr = 1;
+ cp.close_fd_above_stderr = 1;
sbgr = start_bg_command(&cp, bg_wait_cb, NULL,
fsmonitor__start_timeout_sec);
cmd.git_cmd = 1;
cmd.no_stdin = 1;
+ cmd.no_stdout = 1;
+ cmd.no_stderr = 1;
+ cmd.close_fd_above_stderr = 1;
cmd.trace2_child_class = "fsmonitor";
strvec_pushl(&cmd.args, "fsmonitor--daemon", "start", NULL);