X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.cpp;h=91e726f920d5a8418f2fb6346fa7766fba23d7c1;hb=565d5e4871c26bebf0417f290a21e449a6b049e0;hp=e8a1569c7d75bc7514fb35269954f25fd0488500;hpb=c03d51cbbfe9f4f8a28dbabbfc068573a1842b74;p=nssm.git diff --git a/service.cpp b/service.cpp index e8a1569..91e726f 100644 --- a/service.cpp +++ b/service.cpp @@ -791,6 +791,10 @@ int pre_edit_service(int argc, TCHAR **argv) { additional = argv[3]; remainder = 4; } + else if (str_equiv(setting->name, NSSM_NATIVE_OBJECTNAME) && mode == MODE_SETTING) { + additional = argv[3]; + remainder = 4; + } else { additional = argv[remainder]; if (argc < mandatory) return usage(1); @@ -933,6 +937,9 @@ int pre_edit_service(int argc, TCHAR **argv) { /* Unset the parameter. */ value.string = 0; } + else if (remainder == argc) { + value.string = 0; + } else { /* Set the parameter. */ size_t len = 0; @@ -1517,7 +1524,6 @@ int start_service(nssm_service_t *service) { TCHAR cmd[CMD_LENGTH]; if (_sntprintf_s(cmd, _countof(cmd), _TRUNCATE, _T("\"%s\" %s"), service->exe, service->flags) < 0) { log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("command line"), _T("start_service"), 0); - close_output_handles(&si); return stop_service(service, 2, true, true); } @@ -1527,6 +1533,14 @@ int start_service(nssm_service_t *service) { if (service->env) duplicate_environment(service->env); if (service->env_extra) set_environment_block(service->env_extra); + /* Set up I/O redirection. */ + if (get_output_handles(service, &si)) { + log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_GET_OUTPUT_HANDLES_FAILED, service->name, 0); + if (! service->no_console) FreeConsole(); + close_output_handles(&si); + return stop_service(service, 4, true, true); + } + bool inherit_handles = false; if (si.dwFlags & STARTF_USESTDHANDLES) inherit_handles = true; unsigned long flags = service->priority & priority_mask(); @@ -1546,6 +1560,8 @@ int start_service(nssm_service_t *service) { close_output_handles(&si); + if (! service->no_console) FreeConsole(); + /* Restore our environment. */ duplicate_environment(service->initial_env); @@ -1671,15 +1687,18 @@ void CALLBACK end_service(void *arg, unsigned char why) { service->rotate_stdout_online = service->rotate_stderr_online = NSSM_ROTATE_OFFLINE; + /* Use now as a dummy exit time. */ + GetSystemTimeAsFileTime(&service->exit_time); + /* Check exit code */ unsigned long exitcode = 0; TCHAR code[16]; if (service->process_handle) { GetExitCodeProcess(service->process_handle, &exitcode); - if (exitcode == STILL_ACTIVE || get_process_exit_time(service->process_handle, &service->exit_time)) GetSystemTimeAsFileTime(&service->exit_time); + /* Check real exit time. */ + if (exitcode != STILL_ACTIVE) get_process_exit_time(service->process_handle, &service->exit_time); CloseHandle(service->process_handle); } - else GetSystemTimeAsFileTime(&service->exit_time); service->process_handle = 0; @@ -1697,8 +1716,6 @@ void CALLBACK end_service(void *arg, unsigned char why) { if (service->pid) kill_process_tree(service, service->pid, exitcode, service->pid); service->pid = 0; - if (! service->no_console) FreeConsole(); - /* The why argument is true if our wait timed out or false otherwise. Our wait is infinite so why will never be true when called by the system.