From 749363b0dabb5d4e78ce61e4e6b9241c1d95111c Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Wed, 30 Dec 2015 22:22:04 +0000 Subject: [PATCH] Control protocol: Remove 'ROLLBACK' command, add a 'SHUTDOWN' command to replace it. Remove the rollback handler interface from ServiceSet. --- control-cmds.h | 5 +++-- control.cc | 26 +++++++++++++------------- service.cc | 3 --- service.h | 22 ---------------------- 4 files changed, 16 insertions(+), 40 deletions(-) diff --git a/control-cmds.h b/control-cmds.h index 52d389d..263f61a 100644 --- a/control-cmds.h +++ b/control-cmds.h @@ -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 diff --git a/control.cc b/control.cc index c54bbc2..22f4378 100644 --- a/control.cc +++ b/control.cc @@ -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(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--; } diff --git a/service.cc b/service.cc index 2fa88e2..7fb8126 100644 --- a/service.cc +++ b/service.cc @@ -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(); - } } diff --git a/service.h b/service.h index e9809fc..3704250 100644 --- a/service.h +++ b/service.h @@ -362,7 +362,6 @@ class ServiceSet std::list 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 -- 2.25.1