From 00aa215fb4e661d323c96306c57c7c5c5ab61698 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Mon, 19 Mar 2018 22:57:00 +0000 Subject: [PATCH] Handle startup timer expiry using failed_to_start. Reduces code duplication, and probably handles some things that were not being handled correctly. --- src/baseproc-service.cc | 8 ++------ src/includes/service.h | 3 ++- src/service.cc | 21 +++++++++++---------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/baseproc-service.cc b/src/baseproc-service.cc index 61c8270..214bc69 100644 --- a/src/baseproc-service.cc +++ b/src/baseproc-service.cc @@ -310,13 +310,9 @@ void base_process_service::timer_expired() noexcept } else if (pid != -1) { // Starting, start timed out. - log(loglevel_t::WARN, "Service ", get_name(), " with pid ", pid, " exceeded allowed start time."); - stop_dependents(); - if (start_explicit) { - start_explicit = false; - release(); - } + log(loglevel_t::WARN, "Service ", get_name(), " with pid ", pid, " exceeded allowed start time; cancelling."); interrupt_start(); + failed_to_start(false, false); } else { // STARTING / STARTED, and we have a pid: must be restarting (smooth recovery if STARTED) diff --git a/src/includes/service.h b/src/includes/service.h index 017e1af..b13e80e 100644 --- a/src/includes/service.h +++ b/src/includes/service.h @@ -334,7 +334,8 @@ class service_record // Service failed to start (only called when in STARTING state). // dep_failed: whether failure is recorded due to a dependency failing - void failed_to_start(bool dep_failed = false) noexcept; + // immediate_stop: whether to set state as STOPPED and handle complete stop. + void failed_to_start(bool dep_failed = false, bool immediate_stop = true) noexcept; // Run a child process (call after forking). // - args specifies the program arguments including the executable (argv[0]) diff --git a/src/service.cc b/src/service.cc index bf74436..5e6fe4f 100644 --- a/src/service.cc +++ b/src/service.cc @@ -365,24 +365,25 @@ void service_record::started() noexcept } } -void service_record::failed_to_start(bool depfailed) noexcept +void service_record::failed_to_start(bool depfailed, bool immediate_stop) noexcept { - if (have_console) { - bp_sys::tcsetpgrp(0, bp_sys::getpgrp()); - release_console(); + if (immediate_stop) { + service_state = service_state_t::STOPPED; + if (have_console) { + bp_sys::tcsetpgrp(0, bp_sys::getpgrp()); + release_console(); + } } + if (waiting_for_console) { services->unqueue_console(this); waiting_for_console = false; } - log_service_failed(get_name()); - service_state = service_state_t::STOPPED; if (start_explicit) { start_explicit = false; release(false); } - notify_listeners(service_event_t::FAILEDSTART); // Cancel start of dependents: for (auto & dept : dependents) { @@ -406,6 +407,9 @@ void service_record::failed_to_start(bool depfailed) noexcept } } } + + log_service_failed(get_name()); + notify_listeners(service_event_t::FAILEDSTART); } bool service_record::bring_up() noexcept @@ -592,9 +596,6 @@ void service_record::release_console() noexcept bool service_record::interrupt_start() noexcept { - if (onstart_flags.starts_on_console) { - services->unqueue_console(this); - } return true; } -- 2.25.1