}\r
\r
/* Get path of this program */\r
- TCHAR path[MAX_PATH];\r
- GetModuleFileName(0, path, MAX_PATH);\r
-\r
- /* Construct command */\r
- TCHAR command[CMD_LENGTH];\r
- size_t pathlen = _tcslen(path);\r
- if (pathlen + 1 >= VALUE_LENGTH) {\r
- print_message(stderr, NSSM_MESSAGE_PATH_TOO_LONG, NSSM);\r
- return 3;\r
- }\r
- if (_sntprintf_s(command, sizeof(command), _TRUNCATE, _T("\"%s\""), path) < 0) {\r
- print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY_FOR_IMAGEPATH);\r
- return 4;\r
- }\r
+ TCHAR command[MAX_PATH];\r
+ GetModuleFileName(0, command, _countof(command));\r
\r
/* Create the service */\r
service->handle = CreateService(services, service->name, service->name, SC_MANAGER_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, command, 0, 0, 0, 0, 0);\r
/* Check exit code */\r
unsigned long exitcode = 0;\r
TCHAR code[16];\r
- GetExitCodeProcess(service->process_handle, &exitcode);\r
- if (exitcode == STILL_ACTIVE || get_process_exit_time(service->process_handle, &service->exit_time)) GetSystemTimeAsFileTime(&service->exit_time);\r
- CloseHandle(service->process_handle);\r
+ if (service->process_handle) {\r
+ GetExitCodeProcess(service->process_handle, &exitcode);\r
+ if (exitcode == STILL_ACTIVE || get_process_exit_time(service->process_handle, &service->exit_time)) GetSystemTimeAsFileTime(&service->exit_time);\r
+ CloseHandle(service->process_handle);\r
+ }\r
+ else GetSystemTimeAsFileTime(&service->exit_time);\r
\r
service->process_handle = 0;\r
- service->pid = 0;\r
\r
/*\r
Log that the service ended BEFORE logging about killing the process\r
\r
/* Clean up. */\r
if (exitcode == STILL_ACTIVE) exitcode = 0;\r
- kill_process_tree(service, service->pid, exitcode, service->pid);\r
+ if (service->pid) kill_process_tree(service, service->pid, exitcode, service->pid);\r
+ service->pid = 0;\r
\r
/*\r
The why argument is true if our wait timed out or false otherwise.\r