From 76f67c0c6121581070dba33188153cdbf2e665d3 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Mon, 11 Jan 2016 23:52:36 +0000 Subject: [PATCH] Refactor/fix control commands, add a few start/stop alternatives --- src/control-cmds.h | 7 ++++++- src/control.cc | 27 ++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/control-cmds.h b/src/control-cmds.h index 263f61a..31c0b1c 100644 --- a/src/control-cmds.h +++ b/src/control-cmds.h @@ -14,9 +14,11 @@ constexpr static int DINIT_CP_LOADSERVICE = 2; // Start or stop a service: constexpr static int DINIT_CP_STARTSERVICE = 3; constexpr static int DINIT_CP_STOPSERVICE = 4; +constexpr static int DINIT_CP_WAKESERVICE = 5; +constexpr static int DINIT_CP_RELEASESERVICE = 6; // Shutdown: -constexpr static int DINIT_CP_SHUTDOWN = 5; +constexpr static int DINIT_CP_SHUTDOWN = 10; // followed by 1-byte shutdown type @@ -50,6 +52,9 @@ constexpr static int DINIT_RP_SERVICERECORD = 59; // Couldn't find/load service constexpr static int DINIT_RP_NOSERVICE = 60; +// Service is already started/stopped +constexpr static int DINIT_RP_ALREADYSS = 61; + // Information: diff --git a/src/control.cc b/src/control.cc index 22f4378..88431ff 100644 --- a/src/control.cc +++ b/src/control.cc @@ -22,7 +22,8 @@ void ControlConn::processPacket() processFindLoad(pktType); return; } - if (pktType == DINIT_CP_STARTSERVICE || pktType == DINIT_CP_STOPSERVICE) { + if (pktType == DINIT_CP_STARTSERVICE || pktType == DINIT_CP_STOPSERVICE + || pktType == DINIT_CP_WAKESERVICE || pktType == DINIT_CP_RELEASESERVICE) { processStartStop(pktType); return; } @@ -154,24 +155,40 @@ void ControlConn::processStartStop(int pktType) return; } else { - if (pktType == DINIT_CP_STARTSERVICE) { + bool already_there = false; + switch (pktType) { + case DINIT_CP_STARTSERVICE: if (do_pin) { service->pinStart(); } else { service->start(); } - } - else { + already_there = service->getState() == ServiceState::STARTED; + break; + case DINIT_CP_STOPSERVICE: if (do_pin) { service->pinStop(); } else { service->stop(); } + already_there = service->getState() == ServiceState::STOPPED; + break; + case DINIT_CP_WAKESERVICE: + // re-start a stopped service. + // TODO pinning + service->start(false); + already_there = service->getState() == ServiceState::STARTED; + break; + default: /* DINIT_CP_RELEASESERVICE */ + // remove explicit start from a service, without necessarily stopping it. + // TODO. + break; } - char ack_buf[] = { DINIT_RP_ACK }; + char ack_buf[] = { (char)(already_there ? DINIT_RP_ALREADYSS : DINIT_RP_ACK) }; + if (! queuePacket(ack_buf, 1)) return; } -- 2.25.1