From 5105b6b65cc6198e2450c2cb0a4551582c4b5f9b Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Mon, 2 Oct 2017 00:49:35 +0100 Subject: [PATCH] Correct use of SOFT vs WAITS_FOR dependency type in various places. Also fix implementation of WAITS_FOR. SOFT presently behaves the same as WAITS_FOR (but cannot presently be specified as a dependency type in a service description). --- src/load_service.cc | 2 +- src/service.cc | 11 +++++++---- src/tests/tests.cc | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/load_service.cc b/src/load_service.cc index 0110476..45c6c18 100644 --- a/src/load_service.cc +++ b/src/load_service.cc @@ -478,7 +478,7 @@ service_record * dirload_service_set::load_service(const char * name) } else if (setting == "waits-for") { string dependency_name = read_setting_value(i, end); - depends.emplace_back(load_service(dependency_name.c_str()), dependency_type::SOFT); + depends.emplace_back(load_service(dependency_name.c_str()), dependency_type::WAITS_FOR); } else if (setting == "logfile") { logfile = read_setting_value(i, end); diff --git a/src/service.cc b/src/service.cc index 8ae77e0..5ef7d2d 100644 --- a/src/service.cc +++ b/src/service.cc @@ -71,7 +71,7 @@ void service_record::stopped() noexcept // If we are a soft dependency of another target, break the acquisition from that target now: for (auto & dependent : dependents) { - if (dependent->dep_type == dependency_type::SOFT) { + if (dependent->dep_type != dependency_type::REGULAR) { if (dependent->holding_acq) { dependent->holding_acq = false; release(); @@ -826,13 +826,16 @@ void service_record::failed_to_start(bool depfailed) noexcept // Cancel start of dependents: for (auto & dept : dependents) { - if (dept->dep_type == dependency_type::REGULAR) { + switch (dept->dep_type) { + case dependency_type::REGULAR: + case dependency_type::MILESTONE: if (dept->get_from()->service_state == service_state_t::STARTING) { dept->get_from()->prop_failure = true; services->add_prop_queue(dept->get_from()); } - } - else if (dept->dep_type == dependency_type::SOFT) { + break; + case dependency_type::WAITS_FOR: + case dependency_type::SOFT: if (dept->waiting_on) { dept->waiting_on = false; dept->get_from()->dependencyStarted(); diff --git a/src/tests/tests.cc b/src/tests/tests.cc index a759bc9..43d2a4e 100644 --- a/src/tests/tests.cc +++ b/src/tests/tests.cc @@ -5,7 +5,7 @@ #include "test_service.h" constexpr static auto REG = dependency_type::REGULAR; -constexpr static auto SFT = dependency_type::SOFT; +constexpr static auto WAITS = dependency_type::WAITS_FOR; // Test 1: starting a service starts dependencies; stopping the service releases and // stops dependencies. @@ -230,7 +230,7 @@ void test7() service_record *s1 = new service_record(&sset, "test-service-1", service_type::INTERNAL, {}); service_record *s2 = new service_record(&sset, "test-service-2", service_type::INTERNAL, {{s1, REG}}); - service_record *s3 = new service_record(&sset, "test-service-3", service_type::INTERNAL, {{s2, SFT}}); + service_record *s3 = new service_record(&sset, "test-service-3", service_type::INTERNAL, {{s2, WAITS}}); sset.add_service(s1); sset.add_service(s2); sset.add_service(s3); -- 2.25.1