Browse Source

Fix issue causing services to be duplicated

Davin McCall 10 months ago
parent
commit
3b1966676f
3 changed files with 10 additions and 7 deletions
  1. 1 1
      src/includes/service.h
  2. 2 2
      src/load-service.cc
  3. 7 4
      src/service.cc

+ 1 - 1
src/includes/service.h

@@ -889,7 +889,7 @@ class service_set
     }
 
     // Locate an existing service record.
-    service_record *find_service(const std::string &name) noexcept;
+    service_record *find_service(const std::string &name, bool find_placeholders = false) noexcept;
 
     // Load a service description, and dependencies, if there is no existing
     // record for the given name.

+ 2 - 2
src/load-service.cc

@@ -273,7 +273,7 @@ service_record * dirload_service_set::load_reload_service(const char *name, serv
 
     if (reload_svc == nullptr) {
         // First try and find an existing record...
-        service_record *existing = find_service(string(name));
+        service_record *existing = find_service(string(name), true);
         if (existing != nullptr) {
             if (existing == avoid_circular || existing->check_is_loading()) {
                 throw service_cyclic_dependency(name);
@@ -521,7 +521,7 @@ service_record * dirload_service_set::load_reload_service(const char *name, serv
             if (before_ent == name)
                 throw service_cyclic_dependency(name);
 
-            before_svc = find_service(before_ent.c_str());
+            before_svc = find_service(before_ent.c_str(), true);
             if (before_svc != nullptr) {
                 check_cycle(settings.depends, before_svc, name);
             }

+ 7 - 4
src/service.cc

@@ -20,7 +20,7 @@
  * See service.h for details.
  */
 
-// Find the requested service by name (will not find placeholder services).
+// Find the requested service by name.
 static service_record * find_service(const std::list<service_record *> & records,
                                     const char *name) noexcept
 {
@@ -28,16 +28,19 @@ static service_record * find_service(const std::list<service_record *> & records
     list<service_record *>::const_iterator i = records.begin();
     for ( ; i != records.end(); ++i ) {
         if (strcmp((*i)->get_name().c_str(), name) == 0) {
-            if ((*i)->get_type() == service_type_t::PLACEHOLDER) return nullptr;
             return *i;
         }
     }
     return nullptr;
 }
 
-service_record * service_set::find_service(const std::string &name) noexcept
+service_record * service_set::find_service(const std::string &name, bool find_placeholders) noexcept
 {
-    return ::find_service(records, name.c_str());
+    service_record *r = ::find_service(records, name.c_str());
+    if (r != nullptr && !find_placeholders && r->get_type() == service_type_t::PLACEHOLDER) {
+        return nullptr;
+    }
+    return r;
 }
 
 void service_record::prepare_for_unload() noexcept