Remember the reason why a service stopped.
[oweals/dinit.git] / src / includes / service.h
index 246a249d933f25ea919529f03d9f979e465986be..1c9e9c5d65a3b9960a594665d4d35b556d62e478 100644 (file)
@@ -183,6 +183,20 @@ enum class dependency_type
     MILESTONE   // dependency must start successfully, but once started the dependency becomes soft
 };
 
+enum class stopped_reason_t
+{
+    NORMAL,
+
+    // Start failures:
+    DEPFAILED, // A dependency failed to start
+    FAILED,    // failed to start (process terminated)
+       EXECFAILED, // failed to start (couldn't launch process)
+    TIMEDOUT,  // timed out when starting
+
+    // Failure after starting:
+    TERMINATED // process terminated
+};
+
 /* Service dependency record */
 class service_dep
 {
@@ -319,6 +333,8 @@ class service_record
     uid_t socket_uid = -1;  // socket user id or -1
     gid_t socket_gid = -1;  // socket group id or -1
 
+    stopped_reason_t stop_reason = stopped_reason_t::NORMAL;  // reason why stopped
+
     // Data for use by service_set
     public:
     
@@ -617,6 +633,12 @@ class service_record
         }
         depends_on.clear();
     }
+
+    // Why did the service stop?
+    stopped_reason_t get_stop_reason()
+    {
+        return stop_reason;
+    }
 };
 
 inline auto extract_prop_queue(service_record *sr) -> decltype(sr->prop_queue_node) &