Skip to content

Commit cc72760

Browse files
committed
fsmonitor--daemon: background daemon must free the console on windows
Teach "git fsmonitor--daemon run" to call FreeConsole() when started in the background by "git fsmonitor--daemon start" on Windows. The background process was holding a handle to the inherited Win32 console despite being passed stdin/out/err set to /dev/null. This caused command prompts and powershell terminal windows to hang in "exit" waiting for the last console handle to be released. (This problem was not seen in git-bash type terminal windows because they don't have a Win32 console attached to them.) Signed-off-by: Jeff Hostetler <[email protected]>
1 parent d2ed07d commit cc72760

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

builtin/fsmonitor--daemon.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ static int fsmonitor_run_daemon(void)
13021302
return err;
13031303
}
13041304

1305-
static int try_to_run_foreground_daemon(void)
1305+
static int try_to_run_foreground_daemon(int free_console)
13061306
{
13071307
/*
13081308
* Technically, we don't need to probe for an existing daemon
@@ -1320,6 +1320,11 @@ static int try_to_run_foreground_daemon(void)
13201320
the_repository->worktree);
13211321
fflush(stdout);
13221322

1323+
#ifdef GIT_WINDOWS_NATIVE
1324+
if (free_console)
1325+
FreeConsole();
1326+
#endif
1327+
13231328
return !!fsmonitor_run_daemon();
13241329
}
13251330

@@ -1351,6 +1356,7 @@ static int spawn_fsmonitor(pid_t *pid)
13511356
strvec_push(&args, git_exe);
13521357
strvec_push(&args, "fsmonitor--daemon");
13531358
strvec_push(&args, "run");
1359+
strvec_push(&args, "--free-console");
13541360
strvec_pushf(&args, "--ipc-threads=%d", fsmonitor__ipc_threads);
13551361

13561362
*pid = mingw_spawnvpe(args.v[0], args.v, NULL, NULL, in, out, out);
@@ -1514,8 +1520,10 @@ static int try_to_start_background_daemon(void)
15141520
int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
15151521
{
15161522
const char *subcmd;
1523+
int free_console = 0;
15171524

15181525
struct option options[] = {
1526+
OPT_BOOL(0, "free-console", &free_console, N_("free console")),
15191527
OPT_INTEGER(0, "ipc-threads",
15201528
&fsmonitor__ipc_threads,
15211529
N_("use <n> ipc worker threads")),
@@ -1559,7 +1567,7 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
15591567
return !!try_to_start_background_daemon();
15601568

15611569
if (!strcmp(subcmd, "run"))
1562-
return !!try_to_run_foreground_daemon();
1570+
return !!try_to_run_foreground_daemon(free_console);
15631571

15641572
if (!strcmp(subcmd, "stop"))
15651573
return !!do_as_client__send_stop();

0 commit comments

Comments
 (0)