Handle startup timer expiry using failed_to_start.
authorDavin McCall <davmac@davmac.org>
Mon, 19 Mar 2018 22:57:00 +0000 (22:57 +0000)
committerDavin McCall <davmac@davmac.org>
Mon, 19 Mar 2018 22:57:00 +0000 (22:57 +0000)
Reduces code duplication, and probably handles some things that were not
being handled correctly.

src/baseproc-service.cc
src/includes/service.h
src/service.cc

index 61c827067236b3bc9d4f378c72f17a0ba3c04f2a..214bc6928d037a0a3886b4c9ab13005988db9952 100644 (file)
@@ -310,13 +310,9 @@ void base_process_service::timer_expired() noexcept
     }
     else if (pid != -1) {
         // Starting, start timed out.
-        log(loglevel_t::WARN, "Service ", get_name(), " with pid ", pid, " exceeded allowed start time.");
-        stop_dependents();
-        if (start_explicit) {
-            start_explicit = false;
-            release();
-        }
+        log(loglevel_t::WARN, "Service ", get_name(), " with pid ", pid, " exceeded allowed start time; cancelling.");
         interrupt_start();
+        failed_to_start(false, false);
     }
     else {
         // STARTING / STARTED, and we have a pid: must be restarting (smooth recovery if STARTED)
index 017e1afea03380ca62ca112ef34596e10fbe9485..b13e80e4efa177dfde553342b5288aa623ffe29b 100644 (file)
@@ -334,7 +334,8 @@ class service_record
     
     // 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;
+    //   immediate_stop: whether to set state as STOPPED and handle complete stop.
+    void failed_to_start(bool dep_failed = false, bool immediate_stop = true) noexcept;
 
     // Run a child process (call after forking).
     // - args specifies the program arguments including the executable (argv[0])
index bf744368fa49bd7f0c0f2fc1bd2c1d33f598fcf6..5e6fe4fe20ff94fb5dc7dc1f93d98010a8df6bbd 100644 (file)
@@ -365,24 +365,25 @@ void service_record::started() noexcept
     }
 }
 
-void service_record::failed_to_start(bool depfailed) noexcept
+void service_record::failed_to_start(bool depfailed, bool immediate_stop) noexcept
 {
-    if (have_console) {
-        bp_sys::tcsetpgrp(0, bp_sys::getpgrp());
-        release_console();
+    if (immediate_stop) {
+        service_state = service_state_t::STOPPED;
+        if (have_console) {
+            bp_sys::tcsetpgrp(0, bp_sys::getpgrp());
+            release_console();
+        }
     }
+
     if (waiting_for_console) {
         services->unqueue_console(this);
         waiting_for_console = false;
     }
     
-    log_service_failed(get_name());
-    service_state = service_state_t::STOPPED;
     if (start_explicit) {
         start_explicit = false;
         release(false);
     }
-    notify_listeners(service_event_t::FAILEDSTART);
     
     // Cancel start of dependents:
     for (auto & dept : dependents) {
@@ -406,6 +407,9 @@ void service_record::failed_to_start(bool depfailed) noexcept
             }
         }
     }
+
+    log_service_failed(get_name());
+    notify_listeners(service_event_t::FAILEDSTART);
 }
 
 bool service_record::bring_up() noexcept
@@ -592,9 +596,6 @@ void service_record::release_console() noexcept
 
 bool service_record::interrupt_start() noexcept
 {
-    if (onstart_flags.starts_on_console) {
-        services->unqueue_console(this);
-    }
     return true;
 }