X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.cpp;h=164fbc0c2fddab5238e7f2f26baeb40b81b04ed2;hb=2a259b54caa08ef6d4dbc99f6fe7ec97837c25e8;hp=bc3a4711c8364f98d3aea9c011ac39aa4e36d3c4;hpb=fe0f3a497b3ab024c4471458e9c8b9a07388750c;p=nssm.git diff --git a/service.cpp b/service.cpp index bc3a471..164fbc0 100644 --- a/service.cpp +++ b/service.cpp @@ -1721,15 +1721,7 @@ int start_service(nssm_service_t *service) { service->status.dwControlsAccepted = SERVICE_ACCEPT_POWEREVENT | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP; SetServiceStatus(service->status_handle, &service->status); - /* Pre-start hook. */ unsigned long control = NSSM_SERVICE_CONTROL_START; - if (nssm_hook(&hook_threads, service, NSSM_HOOK_EVENT_START, NSSM_HOOK_ACTION_PRE, &control, NSSM_SERVICE_STATUS_DEADLINE, false) == NSSM_HOOK_STATUS_ABORT) { - TCHAR code[16]; - _sntprintf_s(code, _countof(code), _TRUNCATE, _T("%lu"), NSSM_HOOK_STATUS_ABORT); - log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_PRESTART_HOOK_ABORT, NSSM_HOOK_EVENT_START, NSSM_HOOK_ACTION_PRE, service->name, code, 0); - unset_service_environment(service); - return stop_service(service, 5, true, true); - } /* Did another thread receive a stop control? */ if (service->allow_restart) { @@ -1742,6 +1734,15 @@ int start_service(nssm_service_t *service) { return stop_service(service, 4, true, true); } + /* Pre-start hook. May need I/O to have been redirected already. */ + if (nssm_hook(&hook_threads, service, NSSM_HOOK_EVENT_START, NSSM_HOOK_ACTION_PRE, &control, NSSM_SERVICE_STATUS_DEADLINE, false) == NSSM_HOOK_STATUS_ABORT) { + TCHAR code[16]; + _sntprintf_s(code, _countof(code), _TRUNCATE, _T("%lu"), NSSM_HOOK_STATUS_ABORT); + log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_PRESTART_HOOK_ABORT, NSSM_HOOK_EVENT_START, NSSM_HOOK_ACTION_PRE, service->name, code, 0); + unset_service_environment(service); + return stop_service(service, 5, true, true); + } + /* The pre-start hook will have cleaned the environment. */ set_service_environment(service);