From 23f5ee6c5edf1ba82605bdff7b94695bd11ca319 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Sat, 2 Jan 2016 17:22:51 +0000 Subject: [PATCH] Fix: scripted service might not have its start/stop registered if the script finishes too quickly. --- service.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/service.cc b/service.cc index d893a6d..a2a5d8e 100644 --- a/service.cc +++ b/service.cc @@ -162,6 +162,7 @@ void ServiceRecord::process_child_status(struct ev_loop *loop, ev_io * stat_io, if (r != 0) { // We read an errno code; exec() failed, and the service startup failed. + sr->pid = -1; log(LogLevel::ERROR, sr->service_name, ": execution failed: ", strerror(exec_status)); if (sr->service_state == ServiceState::STARTING) { sr->failed_to_start(); @@ -171,7 +172,6 @@ void ServiceRecord::process_child_status(struct ev_loop *loop, ev_io * stat_io, // not to leave the service in STARTED state: sr->stopped(); } - sr->pid = -1; } else { // exec() succeeded. @@ -179,10 +179,10 @@ void ServiceRecord::process_child_status(struct ev_loop *loop, ev_io * stat_io, if (sr->service_state != ServiceState::STARTED) { sr->started(); } - if (sr->pid == -1) { - // Somehow the process managed to complete before we even saw the status. - sr->handle_exit_status(); - } + } + if (sr->pid == -1) { + // Somehow the process managed to complete before we even saw the status. + sr->handle_exit_status(); } } } @@ -599,8 +599,6 @@ bool ServiceRecord::stopDependents() noexcept return all_deps_stopped; } - - // Dependency stopped or is stopping; we must stop too. void ServiceRecord::allDepsStopped() { -- 2.25.1