Fix gentle service stop
authorDavin McCall <davmac@davmac.org>
Sun, 21 Jul 2019 04:57:19 +0000 (14:57 +1000)
committerDavin McCall <davmac@davmac.org>
Sun, 21 Jul 2019 05:05:07 +0000 (15:05 +1000)
Fix some problems with "gentle" service stop as found by test.

src/control.cc

index a418a420250b2b3ccddeb3b404e8b7ec332c9fdf..2f02a24359f3d035d6655053ab4e45081c14b28c 100644 (file)
@@ -178,9 +178,11 @@ bool control_conn_t::process_find_load(int pktType)
 bool control_conn_t::check_dependents(service_record *service, bool &had_dependents)
 {
     std::vector<char> reply_pkt;
+    size_t num_depts = 0;
 
     for (service_dep *dep : service->get_dependents()) {
         if (dep->dep_type == dependency_type::REGULAR) {
+            num_depts++;
             // find or allocate a service handle
             handle_t dept_handle = allocate_service_handle(dep->get_from());
             if (reply_pkt.empty()) {
@@ -195,12 +197,14 @@ bool control_conn_t::check_dependents(service_record *service, bool &had_depende
         }
     }
 
-    had_dependents = !reply_pkt.empty();
-    if (had_dependents) {
-        // We didn't build a reply packet, so there are no affected dependents
-        if (! queue_packet(std::move(reply_pkt))) return false;
+    if (num_depts != 0) {
+        // There are affected dependents
+        had_dependents = true;
+        memcpy(reply_pkt.data() + 1, &num_depts, sizeof(num_depts));
+        return queue_packet(std::move(reply_pkt));
     }
 
+    had_dependents = false;
     return true;
 }
 
@@ -254,7 +258,7 @@ bool control_conn_t::process_start_stop(int pktType)
             if (gentle) {
                 // Check dependents; return appropriate response if any will be affected
                 bool has_dependents;
-                if (check_dependents(service, has_dependents)) {
+                if (check_dependents(service, has_dependents)) {
                     return false;
                 }
                 if (has_dependents) {