Make "pinStart" and "start", and "pinStop" and "stop", separate
authorDavin McCall <davmac@davmac.org>
Wed, 13 Jan 2016 18:49:40 +0000 (18:49 +0000)
committerDavin McCall <davmac@davmac.org>
Wed, 13 Jan 2016 18:49:40 +0000 (18:49 +0000)
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
src/service.cc
src/service.h

index 88431fff935c5b092fbf27b6d7e67ad465dea11b..2efe73128e56c2d65a3ad4100f55950b68978718 100644 (file)
@@ -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;
index e319a6fcb4e725479cd8c2002750ac0bd28dda41..a5c777a73430e8a132ac017f71a31ea2d102aafa 100644 (file)
@@ -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) {
index 64ae15c1d5bd0acffba8f24f06c20257c2bb9c4a..0140168a7e3da9e3c6395198f2f9e9707dcb976b 100644 (file)
@@ -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
     {