HANDLE stdout_handle = append_to_file(service->stdout_path, service->stdout_sharing, 0, service->stdout_disposition, service->stdout_flags);\r
if (! stdout_handle) return 4;\r
\r
- /* Try online rotation only if a size threshold is set. */\r
if (service->rotate_files && service->rotate_stdout_online) {\r
service->stdout_pipe = si->hStdOutput = 0;\r
service->stdout_thread = create_logging_thread(service->name, service->stdout_path, service->stdout_sharing, service->stdout_disposition, service->stdout_flags, &service->stdout_pipe, &si->hStdOutput, &stdout_handle, service->rotate_bytes_low, service->rotate_bytes_high, &service->stdout_tid, &service->rotate_stdout_online);\r
-\r
if (! service->stdout_thread) {\r
- if (! DuplicateHandle(GetCurrentProcess(), stdout_handle, GetCurrentProcess(), &si->hStdOutput, 0, true, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_DUPLICATEHANDLE_FAILED, NSSM_REG_STDOUT, error_string(GetLastError()), 0);\r
- return 4;\r
- }\r
- service->rotate_stdout_online = NSSM_ROTATE_OFFLINE;\r
+ CloseHandle(service->stdout_pipe);\r
+ CloseHandle(si->hStdOutput);\r
+ }\r
+ }\r
+ else service->stdout_thread = 0;\r
+\r
+ if (! service->stdout_thread) {\r
+ if (! DuplicateHandle(GetCurrentProcess(), stdout_handle, GetCurrentProcess(), &si->hStdOutput, 0, true, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_DUPLICATEHANDLE_FAILED, NSSM_REG_STDOUT, error_string(GetLastError()), 0);\r
+ return 4;\r
}\r
+ service->rotate_stdout_online = NSSM_ROTATE_OFFLINE;\r
}\r
\r
set_flags = true;\r
if (service->rotate_files && service->rotate_stderr_online) {\r
service->stderr_pipe = si->hStdError = 0;\r
service->stderr_thread = create_logging_thread(service->name, service->stderr_path, service->stderr_sharing, service->stderr_disposition, service->stderr_flags, &service->stderr_pipe, &si->hStdError, &stderr_handle, service->rotate_bytes_low, service->rotate_bytes_high, &service->stderr_tid, &service->rotate_stderr_online);\r
-\r
if (! service->stderr_thread) {\r
- if (! DuplicateHandle(GetCurrentProcess(), stderr_handle, GetCurrentProcess(), &si->hStdError, 0, true, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_DUPLICATEHANDLE_FAILED, NSSM_REG_STDERR, error_string(GetLastError()), 0);\r
- return 7;\r
- }\r
- service->rotate_stderr_online = NSSM_ROTATE_OFFLINE;\r
+ CloseHandle(service->stderr_pipe);\r
+ CloseHandle(si->hStdError);\r
+ }\r
+ }\r
+ else service->stderr_thread = 0;\r
+\r
+ if (! service->stderr_thread) {\r
+ if (! DuplicateHandle(GetCurrentProcess(), stderr_handle, GetCurrentProcess(), &si->hStdError, 0, true, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_DUPLICATEHANDLE_FAILED, NSSM_REG_STDERR, error_string(GetLastError()), 0);\r
+ return 7;\r
}\r
+ service->rotate_stderr_online = NSSM_ROTATE_OFFLINE;\r
}\r
\r
set_flags = true;\r
}\r
\r
complain_read:\r
- /* Ignore the error if we've been requested to exit for rotation anyway. */\r
- if (*logger->rotate_online == NSSM_ROTATE_ONLINE_ASAP) return ret;\r
+ /* Ignore the error if we've been requested to exit anyway. */\r
+ if (*logger->rotate_online != NSSM_ROTATE_ONLINE) return ret;\r
if (! (*complained & COMPLAINED_READ)) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_READFILE_FAILED, logger->service_name, logger->path, error_string(error), 0);\r
*complained |= COMPLAINED_READ;\r
return ret;\r