]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: add helper to retrieve service.status_text
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 2 Jul 2021 15:00:00 +0000 (17:00 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 Jul 2021 09:33:52 +0000 (11:33 +0200)
src/core/service.c
src/core/unit.h

index 1f38a25476875562f4654784b60bfba7dfa422fd..f4a79dc2af531dde2600036b8d2d295a39f5efb0 100644 (file)
@@ -4379,6 +4379,14 @@ static int service_exit_status(Unit *u) {
         return s->main_exec_status.status;
 }
 
+static const char* service_status_text(Unit *u) {
+        Service *s = SERVICE(u);
+
+        assert(s);
+
+        return s->status_text;
+}
+
 static int service_clean(Unit *u, ExecCleanMask mask) {
         _cleanup_strv_free_ char **l = NULL;
         Service *s = SERVICE(u);
@@ -4590,6 +4598,7 @@ const UnitVTable service_vtable = {
         .get_timeout = service_get_timeout,
         .needs_console = service_needs_console,
         .exit_status = service_exit_status,
+        .status_text = service_status_text,
 
         .status_message_formats = {
                 .finished_start_job = {
index 759104ffa796979ffc5d523f81748a13fdbbf514..48074d8ca5b680b6723d79c043a4c97bc068b459 100644 (file)
@@ -631,6 +631,9 @@ typedef struct UnitVTable {
          * exit code of the "main" process of the service or similar. */
         int (*exit_status)(Unit *u);
 
+        /* Return a copy of the status string pointer. */
+        const char* (*status_text)(Unit *u);
+
         /* Like the enumerate() callback further down, but only enumerates the perpetual units, i.e. all units that
          * unconditionally exist and are always active. The main reason to keep both enumeration functions separate is
          * philosophical: the state of perpetual units should be put in place by coldplug(), while the state of those
@@ -744,6 +747,12 @@ static inline bool unit_is_extrinsic(Unit *u) {
                 (UNIT_VTABLE(u)->is_extrinsic && UNIT_VTABLE(u)->is_extrinsic(u));
 }
 
+static inline const char* unit_status_text(Unit *u) {
+        if (u && UNIT_VTABLE(u)->status_text)
+                return UNIT_VTABLE(u)->status_text(u);
+        return NULL;
+}
+
 void unit_add_to_load_queue(Unit *u);
 void unit_add_to_dbus_queue(Unit *u);
 void unit_add_to_cleanup_queue(Unit *u);