Skip to content

Commit dff7471

Browse files
jeffhostetlergitster
authored andcommitted
fsmonitor--daemon: prepare for adding health thread
Refactor daemon thread startup to make it easier to start a third thread class to monitor the health of the daemon. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3963e68 commit dff7471

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

builtin/fsmonitor--daemon.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,8 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
11741174
*/
11751175
.uds_disallow_chdir = 0
11761176
};
1177+
int listener_started = 0;
1178+
int err = 0;
11771179

11781180
/*
11791181
* Start the IPC thread pool before the we've started the file
@@ -1194,15 +1196,20 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
11941196
if (pthread_create(&state->listener_thread, NULL,
11951197
fsm_listen__thread_proc, state) < 0) {
11961198
ipc_server_stop_async(state->ipc_server_data);
1197-
ipc_server_await(state->ipc_server_data);
1198-
1199-
return error(_("could not start fsmonitor listener thread"));
1199+
err = error(_("could not start fsmonitor listener thread"));
1200+
goto cleanup;
12001201
}
1202+
listener_started = 1;
12011203

12021204
/*
12031205
* The daemon is now fully functional in background threads.
1206+
* Our primary thread should now just wait while the threads
1207+
* do all the work.
1208+
*/
1209+
cleanup:
1210+
/*
12041211
* Wait for the IPC thread pool to shutdown (whether by client
1205-
* request or from filesystem activity).
1212+
* request, from filesystem activity, or an error).
12061213
*/
12071214
ipc_server_await(state->ipc_server_data);
12081215

@@ -1211,10 +1218,16 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
12111218
* event from the IPC thread pool, but it doesn't hurt to tell
12121219
* it again. And wait for it to shutdown.
12131220
*/
1214-
fsm_listen__stop_async(state);
1215-
pthread_join(state->listener_thread, NULL);
1221+
if (listener_started) {
1222+
fsm_listen__stop_async(state);
1223+
pthread_join(state->listener_thread, NULL);
1224+
}
12161225

1217-
return state->error_code;
1226+
if (err)
1227+
return err;
1228+
if (state->error_code)
1229+
return state->error_code;
1230+
return 0;
12181231
}
12191232

12201233
static int fsmonitor_run_daemon(void)

0 commit comments

Comments
 (0)