+ if(!StartService(service, 0, NULL))
+ logger(DEBUG_ALWAYS, LOG_WARNING, "Could not start %s service: %s", identname, winerror(GetLastError()));
+ else
+ logger(DEBUG_ALWAYS, LOG_INFO, "%s service started", identname);
+
+ return true;
+}
+
+io_t stop_io;
+
+DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
+ switch(request) {
+ case SERVICE_CONTROL_INTERROGATE:
+ SetServiceStatus(statushandle, &status);
+ return NO_ERROR;
+ case SERVICE_CONTROL_STOP:
+ logger(DEBUG_ALWAYS, LOG_NOTICE, "Got %s request", "SERVICE_CONTROL_STOP");
+ break;
+ case SERVICE_CONTROL_SHUTDOWN:
+ logger(DEBUG_ALWAYS, LOG_NOTICE, "Got %s request", "SERVICE_CONTROL_SHUTDOWN");
+ break;
+ default:
+ logger(DEBUG_ALWAYS, LOG_WARNING, "Got unexpected request %d", (int)request);
+ return ERROR_CALL_NOT_IMPLEMENTED;
+ }
+
+ status.dwWaitHint = 1000;
+ status.dwCurrentState = SERVICE_STOP_PENDING;
+ SetServiceStatus(statushandle, &status);
+ if (WSASetEvent(stop_io.event) == FALSE)
+ abort();
+ return NO_ERROR;