X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.cpp;h=c920af8b8987e8cbe505deb4b40126332d133aa3;hb=fa2f3fe4a81e6958717ae05f6d37af2da91bcd66;hp=9aa9b019e34c3e56d8db637c0534956c4fee93d9;hpb=49174f884f545ad3716612114e72c44902884f8c;p=nssm.git diff --git a/service.cpp b/service.cpp index 9aa9b01..c920af8 100644 --- a/service.cpp +++ b/service.cpp @@ -1213,7 +1213,10 @@ int control_service(unsigned long control, int argc, TCHAR **argv) { } else { CloseHandle(service_handle); - _ftprintf(stderr, _T("%s: %s %s"), canonical_name, service_control_text(control), error_string(error)); + _ftprintf(stderr, _T("%s: %s: %s"), canonical_name, service_control_text(control), error_string(error)); + if (error == ERROR_SERVICE_NOT_ACTIVE) { + if (control == SERVICE_CONTROL_SHUTDOWN || control == SERVICE_CONTROL_STOP) return 0; + } return 1; } } @@ -1519,6 +1522,7 @@ int start_service(nssm_service_t *service) { bool inherit_handles = false; if (si.dwFlags & STARTF_USESTDHANDLES) inherit_handles = true; unsigned long flags = service->priority & priority_mask(); + if (service->stdin_pipe) flags |= DETACHED_PROCESS; if (service->affinity) flags |= CREATE_SUSPENDED; #ifdef UNICODE flags |= CREATE_UNICODE_ENVIRONMENT; @@ -1611,6 +1615,12 @@ int stop_service(nssm_service_t *service, unsigned long exitcode, bool graceful, UnregisterWait(service->wait_handle); service->wait_handle = 0; } + if (service->stdin_pipe) { + CloseHandle(service->stdin_pipe); + service->stdin_pipe = 0; + } + + service->rotate_stdout_online = service->rotate_stderr_online = NSSM_ROTATE_OFFLINE; if (default_action && ! exitcode && ! graceful) { log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_GRACEFUL_SUICIDE, service->name, service->exe, exit_action_strings[NSSM_EXIT_UNCLEAN], exit_action_strings[NSSM_EXIT_UNCLEAN], exit_action_strings[NSSM_EXIT_UNCLEAN], exit_action_strings[NSSM_EXIT_REALLY], 0); @@ -1659,6 +1669,8 @@ void CALLBACK end_service(void *arg, unsigned char why) { service->stopping = true; + service->rotate_stdout_online = service->rotate_stderr_online = NSSM_ROTATE_OFFLINE; + /* Check exit code */ unsigned long exitcode = 0; TCHAR code[16];