X-Git-Url: http://git.iain.cx/?p=nssm.git;a=blobdiff_plain;f=io.cpp;h=48611b09c57f4719e0d4f43d9f415afa60b0c3c5;hp=0c904be153ade418dac9022b4429e94736ea86a6;hb=ee9a86c8408feaf173733aea12a80211e5d74483;hpb=aecb56aeefcedd850ed274f09b85f62a6f623b5e diff --git a/io.cpp b/io.cpp index 0c904be..48611b0 100644 --- a/io.cpp +++ b/io.cpp @@ -428,6 +428,24 @@ void close_output_handles(STARTUPINFO *si) { if (si->hStdError) CloseHandle(si->hStdError); } +void cleanup_loggers(nssm_service_t *service) { + unsigned long interval = NSSM_CLEANUP_LOGGERS_DEADLINE; + HANDLE thread_handle = INVALID_HANDLE_VALUE; + + close_handle(&service->stdout_thread, &thread_handle); + /* Close write end of the data pipe so logging thread can finalise read. */ + close_handle(&service->stdout_si); + /* Await logging thread then close read end. */ + if (thread_handle != INVALID_HANDLE_VALUE) WaitForSingleObject(thread_handle, interval); + close_handle(&service->stdout_pipe); + + thread_handle = INVALID_HANDLE_VALUE; + close_handle(&service->stderr_thread, &thread_handle); + close_handle(&service->stderr_si); + if (thread_handle != INVALID_HANDLE_VALUE) WaitForSingleObject(thread_handle, interval); + close_handle(&service->stderr_pipe); +} + /* Try multiple times to read from a file. Returns: 0 on success.