Avoid logging service stop after failure to start.
authorDavin McCall <davmac@davmac.org>
Thu, 7 Jun 2018 17:38:10 +0000 (18:38 +0100)
committerDavin McCall <davmac@davmac.org>
Thu, 7 Jun 2018 19:19:40 +0000 (20:19 +0100)
The "FAILED" followed by "STOPPED" is somewhat redundant and arguably
incorrect.

src/includes/service.h
src/service.cc

index d907b09ee2c88bc33e9cd9648884ed66d27b1d89..fabe302254e3a06505e4c80ff80ede7718810a20 100644 (file)
@@ -285,6 +285,7 @@ class service_record
     bool prop_stop    : 1;
 
     bool restarting   : 1;      // re-starting after unexpected termination
+    bool start_failed : 1;      // failed to start (reset when begins starting)
     
     int required_by = 0;        // number of dependents wanting this service to be started
 
@@ -456,7 +457,8 @@ class service_record
             pinned_stopped(false), pinned_started(false), waiting_for_deps(false),
             waiting_for_console(false), have_console(false), waiting_for_execstat(false),
             start_explicit(false), prop_require(false), prop_release(false), prop_failure(false),
-            prop_start(false), prop_stop(false), restarting(false), force_stop(false)
+            prop_start(false), prop_stop(false), restarting(false), start_failed(false),
+            force_stop(false)
     {
         services = set;
         service_name = name;
index 7c87cd0a25063ec5ea9b05c27779aabf047b29af..40060a7df47e5b7e188f159c285606f9866b892e 100644 (file)
@@ -104,7 +104,10 @@ void service_record::stopped() noexcept
         }
     }
 
-    log_service_stopped(service_name);
+    // Start failure will have been logged already, only log if we are stopped for other reasons:
+    if (! start_failed) {
+        log_service_stopped(service_name);
+    }
     notify_listeners(service_event_t::STOPPED);
 }
 
@@ -188,6 +191,7 @@ void service_record::start(bool activate) noexcept
         services->service_active(this);
     }
 
+    start_failed = false;
     service_state = service_state_t::STARTING;
     waiting_for_deps = true;
 
@@ -412,6 +416,7 @@ void service_record::failed_to_start(bool depfailed, bool immediate_stop) noexce
         }
     }
 
+    start_failed = true;
     log_service_failed(get_name());
     notify_listeners(service_event_t::FAILEDSTART);