From 4bd3733ed13907d55c32fe05a1f06338b986bdc7 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Thu, 1 Jun 2017 23:02:15 +0100 Subject: [PATCH] Minor refactoring / code documentation. --- src/service.cc | 21 ++++++++++++--------- src/service.h | 9 ++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/service.cc b/src/service.cc index 6367a6e..08145e2 100644 --- a/src/service.cc +++ b/src/service.cc @@ -65,10 +65,12 @@ void ServiceSet::stopService(const std::string & name) noexcept } } -// Called when a service has actually stopped; dependents have stopped already. +// Called when a service has actually stopped; dependents have stopped already, unless this stop +// is due to an unexpected process termination. void ServiceRecord::stopped() noexcept { - if (service_type != ServiceType::SCRIPTED && service_type != ServiceType::BGPROCESS && onstart_flags.runs_on_console) { + if (service_type != ServiceType::SCRIPTED && service_type != ServiceType::BGPROCESS + && onstart_flags.runs_on_console) { tcsetpgrp(0, getpgrp()); discard_console_log_buffer(); releaseConsole(); @@ -77,7 +79,9 @@ void ServiceRecord::stopped() noexcept force_stop = false; // If we are a soft dependency of another target, break the acquisition from that target now: - bool will_restart = (desired_state == ServiceState::STARTED) && service_set->get_auto_restart(); + bool will_restart = (desired_state == ServiceState::STARTED) + && service_set->get_auto_restart(); + if (! will_restart) { for (auto dependency : soft_dpts) { if (dependency->holding_acq) { @@ -89,14 +93,17 @@ void ServiceRecord::stopped() noexcept will_restart &= (desired_state == ServiceState::STARTED); for (auto dependency : depends_on) { + // we signal dependencies in case they are waiting for us to stop - but only if we won't + // restart or if they are stopping uninterruptibly. if (! will_restart || ! dependency->can_interrupt_stop()) { dependency->dependentStopped(); } } + service_state = ServiceState::STOPPED; + if (will_restart) { // Desired state is "started". - service_state = ServiceState::STOPPED; service_set->addToStartQueue(this); } else { @@ -109,11 +116,7 @@ void ServiceRecord::stopped() noexcept start_explicit = false; release(); } - - service_state = ServiceState::STOPPED; - if (required_by == 0) { - // Since state wasn't STOPPED until now, any release performed above won't have marked - // the service inactive. We check for that now: + else if (required_by == 0) { service_set->service_inactive(this); } } diff --git a/src/service.h b/src/service.h index d7bdd1e..671de17 100644 --- a/src/service.h +++ b/src/service.h @@ -753,7 +753,8 @@ class ServiceSet // transition to the 'stopped' state. void stopService(const std::string &name) noexcept; - // Add a service record to the state propogation queue + // Add a service record to the state propagation queue. The service record will have its + // do_propagation() method called when the queue is processed. void addToPropQueue(ServiceRecord *service) noexcept { if (service->next_in_prop_queue == nullptr && first_prop_queue != service) { @@ -762,14 +763,16 @@ class ServiceSet } } - // Add a service record to the start queue; called by service record + // Add a service record to the start queue. The service record will have its + // execute_transition() method called when the queue is processed. void addToStartQueue(ServiceRecord *service) noexcept { // The start/stop queue is actually one queue: addToStopQueue(service); } - // Add a service to the stop queue; called by service record + // Add a service record to the stop queue. The service record will have its + // execute_transition() method called when the queue is processed. void addToStopQueue(ServiceRecord *service) noexcept { if (service->next_in_stop_queue == nullptr && first_stop_queue != service) { -- 2.25.1