From 477e1da52e7c55da4fd56b1a48ae6a22a4aaa8bb Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Wed, 13 Jan 2016 18:49:40 +0000 Subject: [PATCH] Make "pinStart" and "start", and "pinStop" and "stop", separate operations. "pinStart" and "pinStop" set the pin for the started and stopped states respectively, but do not attempt to move the service into the chosen state. --- src/control.cc | 18 +++++------------- src/service.cc | 12 ------------ src/service.h | 19 ++++++++++++++++--- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/control.cc b/src/control.cc index 88431ff..2efe731 100644 --- a/src/control.cc +++ b/src/control.cc @@ -158,26 +158,18 @@ void ControlConn::processStartStop(int pktType) bool already_there = false; switch (pktType) { case DINIT_CP_STARTSERVICE: - if (do_pin) { - service->pinStart(); - } - else { - service->start(); - } + if (do_pin) service->pinStart(); + service->start(); already_there = service->getState() == ServiceState::STARTED; break; case DINIT_CP_STOPSERVICE: - if (do_pin) { - service->pinStop(); - } - else { - service->stop(); - } + if (do_pin) service->pinStop(); + service->stop(); already_there = service->getState() == ServiceState::STOPPED; break; case DINIT_CP_WAKESERVICE: // re-start a stopped service. - // TODO pinning + if (do_pin) service->pinStart(); service->start(false); already_there = service->getState() == ServiceState::STARTED; break; diff --git a/src/service.cc b/src/service.cc index e319a6f..a5c777a 100644 --- a/src/service.cc +++ b/src/service.cc @@ -845,18 +845,6 @@ void ServiceRecord::allDepsStopped() } } -void ServiceRecord::pinStart() noexcept -{ - start(true); - pinned_started = true; -} - -void ServiceRecord::pinStop() noexcept -{ - stop(); - pinned_stopped = true; -} - void ServiceRecord::unpin() noexcept { if (pinned_started) { diff --git a/src/service.h b/src/service.h index 64ae15c..0140168 100644 --- a/src/service.h +++ b/src/service.h @@ -436,9 +436,22 @@ class ServiceRecord void forceStop() noexcept; // force-stop this service and all dependents - void pinStart() noexcept; // start the service and pin it - void pinStop() noexcept; // stop the service and pin it - void unpin() noexcept; // unpin the service + // Pin the service in "started" state (when it reaches the state) + void pinStart() noexcept + { + pinned_started = true; + } + + // Pin the service in "stopped" state (when it reaches the state) + void pinStop() noexcept + { + pinned_stopped = true; + } + + // Remove both "started" and "stopped" pins. If the service is currently pinned + // in either state but would naturally be in the opposite state, it will immediately + // commence starting/stopping. + void unpin() noexcept; bool isDummy() noexcept { -- 2.25.1