From: Jeff Hostetler Date: Thu, 03 Mar 2022 16:16:01 GMT Subject: Re: [PATCH 17/23] fsmonitor--daemon: stub in health thread Message-ID: <5bb246d3-82d0-835a-cfc4-be2824479a82@jeffhostetler.com> In-Reply-To: <4c784936-7b70-3910-6413-0438e86b23c4@github.com> On 2/24/22 11:04 AM, Derrick Stolee wrote: > On 2/15/2022 10:59 AM, Jeff Hostetler via GitGitGadget wrote: >> From: Jeff Hostetler >> >> Create another thread to watch over the daemon process and >> automatically shut it down if necessary. >> >> This commit creates the basic framework for a "health" thread >> to monitor the daemon and/or the file system. Later commits >> will add platform-specific code to do the actual work. > > ... ... > >> diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c >> new file mode 100644 >> index 00000000000..94b1d020f25 >> --- /dev/null >> +++ b/compat/fsmonitor/fsm-health-win32.c >> @@ -0,0 +1,72 @@ >> +#include "cache.h" >> +#include "config.h" >> +#include "fsmonitor.h" >> +#include "fsm-health.h" >> +#include "fsmonitor--daemon.h" >> + >> +struct fsm_health_data >> +{ >> + HANDLE hEventShutdown; >> + >> + HANDLE hHandles[1]; /* the array does not own these handles */ >> +#define HEALTH_SHUTDOWN 0 >> + int nr_handles; /* number of active event handles */ >> +}; >> + >> +int fsm_health__ctor(struct fsmonitor_daemon_state *state) >> +{ >> + struct fsm_health_data *data; >> + >> + CALLOC_ARRAY(data, 1); >> + >> + data->hEventShutdown = CreateEvent(NULL, TRUE, FALSE, NULL); >> + >> + data->hHandles[HEALTH_SHUTDOWN] = data->hEventShutdown; >> + data->nr_handles++; >> + >> + state->health_data = data; >> + return 0; >> +} >> + >> +void fsm_health__dtor(struct fsmonitor_daemon_state *state) >> +{ >> + struct fsm_health_data *data; >> + >> + if (!state || !state->health_data) >> + return; >> + >> + data = state->health_data; >> + >> + CloseHandle(data->hEventShutdown); >> + >> + FREE_AND_NULL(state->health_data); >> +} >> + >> +void fsm_health__loop(struct fsmonitor_daemon_state *state) >> +{ >> + struct fsm_health_data *data = state->health_data; >> + >> + for (;;) { >> + DWORD dwWait = WaitForMultipleObjects(data->nr_handles, >> + data->hHandles, >> + FALSE, INFINITE); >> + >> + if (dwWait == WAIT_OBJECT_0 + HEALTH_SHUTDOWN) >> + goto clean_shutdown; >> + >> + error(_("health thread wait failed [GLE %ld]"), >> + GetLastError()); >> + goto force_error_stop; >> + } >> + >> +force_error_stop: >> + state->health_error_code = -1; >> + ipc_server_stop_async(state->ipc_server_data); >> +clean_shutdown: >> + return; >> +} >> + >> +void fsm_health__stop_async(struct fsmonitor_daemon_state *state) >> +{ >> + SetEvent(state->health_data->hHandles[HEALTH_SHUTDOWN]); >> +} > > But it apppears the Windows code is actually implemented. Did you > mean to do that as separate step, or should the commit message > mention that the Windows implementation is included? The Windows version stubs in just enough of the thread-proc to keep the health thread alive and waiting for a shutdown event. It doesn'ta actually have any health monitor in it yet. I'll update the commit message to clarify. Thanks Jeff