Correct use of SOFT vs WAITS_FOR dependency type in various places.
authorDavin McCall <davmac@davmac.org>
Sun, 1 Oct 2017 23:49:35 +0000 (00:49 +0100)
committerDavin McCall <davmac@davmac.org>
Sun, 1 Oct 2017 23:49:35 +0000 (00:49 +0100)
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
src/service.cc
src/tests/tests.cc

index 0110476549c4b3f3afd38cd4cf4e1f30ec06a25e..45c6c189b2313a061427f854ab38b4102e475ccd 100644 (file)
@@ -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);
index 8ae77e06a3045bf645d507c2809932fd912c119d..5ef7d2dbbc89f5df294b2719058760e76b997f17 100644 (file)
@@ -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();
index a759bc9d9a8dc368dd9f18fdc840a397ea4bbaeb..43d2a4e0bc3c2d0d68352d64c563382461d14743 100644 (file)
@@ -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);