Fixed regression with offline rotation.

We weren't falling through to direct I/O when online rotation was
completely disabled, only when it was attempted but failed.
We weren't closing pipe handles after a failed attempt to enable online
rotation.
We were incorrectly complaining about I/O errors in the event log when the
application was exiting.
master
Iain Patterson 11 years ago
parent e0b8c55377
commit e0f182e26d

@ -276,10 +276,15 @@ int get_output_handles(nssm_service_t *service, HKEY key, STARTUPINFO *si) {
HANDLE stdout_handle = append_to_file(service->stdout_path, service->stdout_sharing, 0, service->stdout_disposition, service->stdout_flags); HANDLE stdout_handle = append_to_file(service->stdout_path, service->stdout_sharing, 0, service->stdout_disposition, service->stdout_flags);
if (! stdout_handle) return 4; if (! stdout_handle) return 4;
/* Try online rotation only if a size threshold is set. */
if (service->rotate_files && service->rotate_stdout_online) { if (service->rotate_files && service->rotate_stdout_online) {
service->stdout_pipe = si->hStdOutput = 0; service->stdout_pipe = si->hStdOutput = 0;
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); 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);
if (! service->stdout_thread) {
CloseHandle(service->stdout_pipe);
CloseHandle(si->hStdOutput);
}
}
else service->stdout_thread = 0;
if (! service->stdout_thread) { if (! service->stdout_thread) {
if (! DuplicateHandle(GetCurrentProcess(), stdout_handle, GetCurrentProcess(), &si->hStdOutput, 0, true, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { if (! DuplicateHandle(GetCurrentProcess(), stdout_handle, GetCurrentProcess(), &si->hStdOutput, 0, true, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
@ -288,7 +293,6 @@ int get_output_handles(nssm_service_t *service, HKEY key, STARTUPINFO *si) {
} }
service->rotate_stdout_online = NSSM_ROTATE_OFFLINE; service->rotate_stdout_online = NSSM_ROTATE_OFFLINE;
} }
}
set_flags = true; set_flags = true;
} }
@ -323,6 +327,12 @@ int get_output_handles(nssm_service_t *service, HKEY key, STARTUPINFO *si) {
if (service->rotate_files && service->rotate_stderr_online) { if (service->rotate_files && service->rotate_stderr_online) {
service->stderr_pipe = si->hStdError = 0; service->stderr_pipe = si->hStdError = 0;
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); 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);
if (! service->stderr_thread) {
CloseHandle(service->stderr_pipe);
CloseHandle(si->hStdError);
}
}
else service->stderr_thread = 0;
if (! service->stderr_thread) { if (! service->stderr_thread) {
if (! DuplicateHandle(GetCurrentProcess(), stderr_handle, GetCurrentProcess(), &si->hStdError, 0, true, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { if (! DuplicateHandle(GetCurrentProcess(), stderr_handle, GetCurrentProcess(), &si->hStdError, 0, true, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
@ -331,7 +341,6 @@ int get_output_handles(nssm_service_t *service, HKEY key, STARTUPINFO *si) {
} }
service->rotate_stderr_online = NSSM_ROTATE_OFFLINE; service->rotate_stderr_online = NSSM_ROTATE_OFFLINE;
} }
}
set_flags = true; set_flags = true;
} }
@ -390,8 +399,8 @@ static int try_read(logger_t *logger, void *address, unsigned long bufsize, unsi
} }
complain_read: complain_read:
/* Ignore the error if we've been requested to exit for rotation anyway. */ /* Ignore the error if we've been requested to exit anyway. */
if (*logger->rotate_online == NSSM_ROTATE_ONLINE_ASAP) return ret; if (*logger->rotate_online != NSSM_ROTATE_ONLINE) return ret;
if (! (*complained & COMPLAINED_READ)) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_READFILE_FAILED, logger->service_name, logger->path, error_string(error), 0); if (! (*complained & COMPLAINED_READ)) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_READFILE_FAILED, logger->service_name, logger->path, error_string(error), 0);
*complained |= COMPLAINED_READ; *complained |= COMPLAINED_READ;
return ret; return ret;

@ -1612,6 +1612,8 @@ int stop_service(nssm_service_t *service, unsigned long exitcode, bool graceful,
service->wait_handle = 0; service->wait_handle = 0;
} }
service->rotate_stdout_online = service->rotate_stderr_online = NSSM_ROTATE_OFFLINE;
if (default_action && ! exitcode && ! graceful) { 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); 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);
graceful = true; graceful = true;
@ -1659,6 +1661,8 @@ void CALLBACK end_service(void *arg, unsigned char why) {
service->stopping = true; service->stopping = true;
service->rotate_stdout_online = service->rotate_stderr_online = NSSM_ROTATE_OFFLINE;
/* Check exit code */ /* Check exit code */
unsigned long exitcode = 0; unsigned long exitcode = 0;
TCHAR code[16]; TCHAR code[16];

Loading…
Cancel
Save