return 1;\r
}\r
\r
-HANDLE append_to_file(TCHAR *path, unsigned long sharing, SECURITY_ATTRIBUTES *attributes, unsigned long disposition, unsigned long flags) {\r
- HANDLE ret;\r
-\r
- /* Try to append to the file first. */\r
- ret = CreateFile(path, FILE_APPEND_DATA, sharing, attributes, disposition, flags, 0);\r
+HANDLE write_to_file(TCHAR *path, unsigned long sharing, SECURITY_ATTRIBUTES *attributes, unsigned long disposition, unsigned long flags) {\r
+ HANDLE ret = CreateFile(path, FILE_WRITE_DATA, sharing, attributes, disposition, flags, 0);\r
if (ret) {\r
- SetEndOfFile(ret);\r
+ if (SetFilePointer(ret, 0, 0, FILE_END) != INVALID_SET_FILE_POINTER) SetEndOfFile(ret);\r
return ret;\r
}\r
\r
- unsigned long error = GetLastError();\r
- if (error != ERROR_FILE_NOT_FOUND) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CREATEFILE_FAILED, path, error_string(error), 0);\r
- return (HANDLE) 0;\r
- }\r
-\r
- /* It didn't exist. Create it. */\r
- ret = CreateFile(path, FILE_WRITE_DATA, sharing, attributes, disposition, flags, 0);\r
- if (! ret) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CREATEFILE_FAILED, path, error_string(GetLastError()), 0);\r
-\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CREATEFILE_FAILED, path, error_string(GetLastError()), 0);\r
return ret;\r
}\r
\r
}\r
if (si && service->stdout_path[0]) {\r
if (service->rotate_files) rotate_file(service->name, service->stdout_path, service->rotate_seconds, service->rotate_bytes_low, service->rotate_bytes_high);\r
- HANDLE stdout_handle = append_to_file(service->stdout_path, service->stdout_sharing, 0, service->stdout_disposition, service->stdout_flags);\r
+ HANDLE stdout_handle = write_to_file(service->stdout_path, service->stdout_sharing, 0, service->stdout_disposition, service->stdout_flags);\r
if (! stdout_handle) return 4;\r
\r
if (service->rotate_files && service->rotate_stdout_online) {\r
}\r
else if (si) {\r
if (service->rotate_files) rotate_file(service->name, service->stderr_path, service->rotate_seconds, service->rotate_bytes_low, service->rotate_bytes_high);\r
- HANDLE stderr_handle = append_to_file(service->stderr_path, service->stderr_sharing, 0, service->stderr_disposition, service->stderr_flags);\r
+ HANDLE stderr_handle = write_to_file(service->stderr_path, service->stderr_sharing, 0, service->stderr_disposition, service->stderr_flags);\r
if (! stderr_handle) return 7;\r
\r
if (service->rotate_files && service->rotate_stderr_online) {\r
}\r
\r
/* Reopen. */\r
- logger->write_handle = append_to_file(logger->path, logger->sharing, 0, logger->disposition, logger->flags);\r
+ logger->write_handle = write_to_file(logger->path, logger->sharing, 0, logger->disposition, logger->flags);\r
if (! logger->write_handle) {\r
error = GetLastError();\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CREATEFILE_FAILED, logger->path, error_string(error), 0);\r
int get_createfile_parameters(HKEY, TCHAR *, TCHAR *, unsigned long *, unsigned long, unsigned long *, unsigned long, unsigned long *, unsigned long);\r
int set_createfile_parameter(HKEY, TCHAR *, TCHAR *, unsigned long);\r
int delete_createfile_parameter(HKEY, TCHAR *, TCHAR *);\r
-HANDLE append_to_file(TCHAR *, unsigned long, SECURITY_ATTRIBUTES *, unsigned long, unsigned long);\r
+HANDLE write_to_file(TCHAR *, unsigned long, SECURITY_ATTRIBUTES *, unsigned long, unsigned long);\r
void rotate_file(TCHAR *, TCHAR *, unsigned long, unsigned long, unsigned long);\r
int get_output_handles(nssm_service_t *, HKEY, STARTUPINFO *);\r
void close_output_handles(STARTUPINFO *);\r