X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fprocess.c;h=98f4d33a811d0e9c3d6edd8d1a2a3d3413a7d29b;hb=313a752cb5fbf27450d34c15b0085d2d8a4147af;hp=c1038bcd62165728a026742ab1034b44c40ca7ec;hpb=57991e264202ad83e2c1b663777b358bf5573652;p=tinc diff --git a/src/process.c b/src/process.c index c1038bcd..98f4d33a 100644 --- a/src/process.c +++ b/src/process.c @@ -108,6 +108,8 @@ static bool install_service(void) { return true; } +static io_t stop_io; + DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) { switch(request) { case SERVICE_CONTROL_INTERROGATE: @@ -124,16 +126,25 @@ DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) { return ERROR_CALL_NOT_IMPLEMENTED; } - event_exit(); - status.dwWaitHint = 30000; + status.dwWaitHint = 1000; status.dwCurrentState = SERVICE_STOP_PENDING; SetServiceStatus(statushandle, &status); + if (WSASetEvent(stop_io.event) == FALSE) + abort(); return NO_ERROR; } +static void stop_handler(void *data, int flags) { + event_exit(); +} + VOID WINAPI run_service(DWORD argc, LPTSTR* argv) { extern int main2(int argc, char **argv); + io_add_event(&stop_io, stop_handler, NULL, WSACreateEvent()); + if (stop_io.event == FALSE) + abort(); + status.dwServiceType = SERVICE_WIN32; status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; status.dwWin32ExitCode = 0; @@ -160,6 +171,9 @@ VOID WINAPI run_service(DWORD argc, LPTSTR* argv) { SetServiceStatus(statushandle, &status); } + if (WSACloseEvent(stop_io.event) == FALSE) + abort(); + io_del(&stop_io); return; }