Control protocol: Remove 'ROLLBACK' command, add a 'SHUTDOWN'
authorDavin McCall <davmac@davmac.org>
Wed, 30 Dec 2015 22:22:04 +0000 (22:22 +0000)
committerDavin McCall <davmac@davmac.org>
Wed, 30 Dec 2015 22:22:04 +0000 (22:22 +0000)
command to replace it. Remove the rollback handler interface
from ServiceSet.

control-cmds.h
control.cc
service.cc
service.h

index 52d389d38aaf31add96e9d8a17e83c02a48b6220..263f61aaccdbf82f0555126455bb90faa45d2793 100644 (file)
@@ -15,8 +15,9 @@ constexpr static int DINIT_CP_LOADSERVICE = 2;
 constexpr static int DINIT_CP_STARTSERVICE = 3;
 constexpr static int DINIT_CP_STOPSERVICE  = 4;
 
-// Roll-back all services:
-constexpr static int DINIT_CP_ROLLBACKALL = 5;
+// Shutdown:
+constexpr static int DINIT_CP_SHUTDOWN = 5;
+ // followed by 1-byte shutdown type
 
 
 
index c54bbc200fbb99be35888a1415268fc30b553190..22f43785551bb2f81164053b11bef8601d4c8de0 100644 (file)
@@ -26,21 +26,22 @@ void ControlConn::processPacket()
         processStartStop(pktType);
         return;
     }
-    else if (pktType == DINIT_CP_ROLLBACKALL) {
-        // Roll-back all services
-        if (service_set->setRollbackHandler(this)) {
-            service_set->stop_all_services();
-            log_to_console = true;
-            char ackBuf[] = { DINIT_RP_ACK };
-            if (! queuePacket(ackBuf, 1)) return;
-        }
-        else {
-            char nakBuf[] = { DINIT_RP_NAK };
-            if (! queuePacket(nakBuf, 1)) return;
+    else if (pktType == DINIT_CP_SHUTDOWN) {
+        // Shutdown/reboot
+        if (rbuf.get_length() < 2) {
+            chklen = 2;
+            return;
         }
         
+        auto sd_type = static_cast<ShutdownType>(rbuf[1]);
+        
+        service_set->stop_all_services(sd_type);
+        log_to_console = true;
+        char ackBuf[] = { DINIT_RP_ACK };
+        if (! queuePacket(ackBuf, 1)) return;
+        
         // Clear the packet from the buffer
-        rbuf.consume(1);
+        rbuf.consume(2);
         chklen = 0;
         return;
     }
@@ -414,6 +415,5 @@ ControlConn::~ControlConn() noexcept
         p.first->removeListener(this);
     }
     
-    service_set->clearRollbackHandler(this);
     active_control_conns--;
 }
index 2fa88e284953126efb903c88dd56f0b8a658c08c..7fb812625a8e7c54e492d68840d1c8c236cd7587 100644 (file)
@@ -582,7 +582,4 @@ void ServiceSet::service_active(ServiceRecord *sr) noexcept
 void ServiceSet::service_inactive(ServiceRecord *sr) noexcept
 {
     active_services--;
-    if (active_services == 0 && rollback_handler != nullptr) {
-        rollback_handler->rollbackComplete();
-    }
 }
index e9809fc639f644aec6342320f999bd010ecfbd33..3704250ea2aed22574060329bf3e6d0c3520fadd 100644 (file)
--- a/service.h
+++ b/service.h
@@ -362,7 +362,6 @@ class ServiceSet
     std::list<ServiceRecord *> records;
     const char *service_dir;  // directory containing service descriptions
     bool restart_enabled; // whether automatic restart is enabled (allowed)
-    ControlConn *rollback_handler; // recieves notification when all services stopped
     
     ShutdownType shutdown_type = ShutdownType::CONTINUE;  // Shutdown type, if stopping
     
@@ -451,27 +450,6 @@ class ServiceSet
     {
         return shutdown_type;
     }
-    
-    // Set the rollback handler, which will be notified when all services have stopped.
-    // There can be only one rollback handler; attempts to set it when already set will
-    // fail. Returns true if successful.
-    bool setRollbackHandler(ControlConn *conn) noexcept
-    {
-        if (rollback_handler == nullptr) {
-            rollback_handler = conn;
-            return true;
-        }
-        else {
-            return false;
-        }
-    }
-    
-    void clearRollbackHandler(ControlConn *conn) noexcept
-    {
-        if (rollback_handler == conn) {
-            rollback_handler = nullptr;
-        }
-    }
 };
 
 #endif