Allow relative paths for I/O redirection.

Change to the startup directory before redirecting I/O streams so that
relative paths can be specified.  Then change back so we don't tie up
the directory.
master
Iain Patterson 11 years ago
parent 8febc05f51
commit 9f3d08676d

@ -121,7 +121,7 @@ int get_output_handles(HKEY key, STARTUPINFO *si) {
/* stderr */
if (get_createfile_parameters(key, NSSM_REG_STDERR, path, &sharing, NSSM_STDERR_SHARING, &disposition, NSSM_STDERR_DISPOSITION, &flags, NSSM_STDERR_FLAGS)) return 6;
if (path[0]) {
/* Same as stdin? */
/* Same as stdout? */
if (str_equiv(path, stdout_path)) {
/* Two handles to the same file will create a race. */
if (! DuplicateHandle(GetCurrentProcess(), si->hStdOutput, GetCurrentProcess(), &si->hStdError, 0, true, DUPLICATE_SAME_ACCESS)) {

@ -387,13 +387,22 @@ int get_parameters(nssm_service_t *service, STARTUPINFO *si) {
}
}
/* Change to startup directory in case stdout/stderr are relative paths. */
TCHAR cwd[MAX_PATH];
GetCurrentDirectory(_countof(cwd), cwd);
SetCurrentDirectory(service->dir);
/* Try to get stdout and stderr */
if (get_output_handles(key, si)) {
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_GET_OUTPUT_HANDLES_FAILED, service->name, 0);
RegCloseKey(key);
SetCurrentDirectory(cwd);
return 5;
}
/* Change back in case the startup directory needs to be deleted. */
SetCurrentDirectory(cwd);
/* Try to get throttle restart delay */
override_milliseconds(service->name, key, NSSM_REG_THROTTLE, &service->throttle_delay, NSSM_RESET_THROTTLE_RESTART, NSSM_EVENT_BOGUS_THROTTLE);

Loading…
Cancel
Save