Refactoring: remove unneeded method
authorDavin McCall <davmac@davmac.org>
Thu, 7 Jan 2016 20:45:09 +0000 (20:45 +0000)
committerDavin McCall <davmac@davmac.org>
Thu, 7 Jan 2016 20:45:09 +0000 (20:45 +0000)
src/service.cc
src/service.h

index 4fec13be7f7a51d20fa81a7e054f64dfa4389958..c4667bbcfd1055cc66030173666487c46e87fe9f 100644 (file)
@@ -506,9 +506,9 @@ void ServiceRecord::started() noexcept
     }
 }
 
-void ServiceRecord::failed_to_start()
+void ServiceRecord::failed_to_start(bool depfailed) noexcept
 {
-    if (onstart_flags.runs_on_console) {
+    if (!depfailed && onstart_flags.runs_on_console) {
         tcsetpgrp(0, getpgrp());
         releaseConsole();
     }
@@ -519,11 +519,10 @@ void ServiceRecord::failed_to_start()
     service_set->service_inactive(this);
     notifyListeners(ServiceEvent::FAILEDSTART);
     
-    // failure to start
     // Cancel start of dependents:
     for (sr_iter i = dependents.begin(); i != dependents.end(); i++) {
         if ((*i)->service_state == ServiceState::STARTING) {
-            (*i)->failed_dependency();
+            (*i)->failed_to_start(true);
         }
     }    
     for (auto i = soft_dpts.begin(); i != soft_dpts.end(); i++) {
@@ -666,30 +665,6 @@ void ServiceRecord::forceStop() noexcept
     }
 }
 
-// A dependency of this service failed to start.
-// Only called when state == STARTING.
-void ServiceRecord::failed_dependency()
-{
-    desired_state = ServiceState::STOPPED;
-    
-    // Presumably, we were starting. So now we're not.
-    service_state = ServiceState::STOPPED;
-    service_set->service_inactive(this);
-    logServiceFailed(service_name);
-    
-    // Notify dependents of this service also
-    for (auto i = dependents.begin(); i != dependents.end(); i++) {
-        if ((*i)->service_state == ServiceState::STARTING) {
-            (*i)->failed_dependency();
-        }
-    }
-    for (auto i = soft_dpts.begin(); i != soft_dpts.end(); i++) {
-        // It's a soft dependency, so send them 'started' rather than
-        // 'failed dep'.
-        (*i)->getFrom()->dependencyStarted();
-    }    
-}
-
 void ServiceRecord::dependentStopped() noexcept
 {
     if (service_state == ServiceState::STOPPING) {
index cbeab725f0b0da35db41555c744fcf67f1aeb534..3d7bc45701ee3469bf374c94803b2ef72a531aed 100644 (file)
@@ -235,12 +235,10 @@ class ServiceRecord
     // Service has successfully started
     void started() noexcept;
     
-    // Service failed to start
-    void failed_to_start();
-    
-    // A dependency of this service failed to start.
-    void failed_dependency();
-    
+    // Service failed to start (only called when in STARTING state).
+    //   dep_failed: whether failure is recorded due to a dependency failing
+    void failed_to_start(bool dep_failed = false) noexcept;
+
     // For process services, start the process, return true on success
     bool start_ps_process() noexcept;
     bool start_ps_process(const std::vector<const char *> &args, bool on_console) noexcept;