chiark / gitweb /
systemctl: show sub state along active state
authorLennart Poettering <lennart@poettering.net>
Tue, 13 Apr 2010 18:59:01 +0000 (20:59 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 13 Apr 2010 18:59:01 +0000 (20:59 +0200)
12 files changed:
automount.c
dbus-manager.c
dbus-unit.c
device.c
mount.c
service.c
socket.c
systemctl.vala
systemd-interfaces.vala
target.c
unit.c
unit.h

index c6ce25d8b254eba93bcc815437bb3e798c906fc0..1192949d837f0996af79e134bb8db2875cfbf3f1 100644 (file)
@@ -93,6 +93,12 @@ static UnitActiveState automount_active_state(Unit *u) {
         return state_translation_table[AUTOMOUNT(u)->state];
 }
 
+static const char *automount_sub_state_to_string(Unit *u) {
+        assert(u);
+
+        return state_string_table[AUTOMOUNT(u)->state];
+}
+
 const UnitVTable automount_vtable = {
         .suffix = ".mount",
 
@@ -104,5 +110,6 @@ const UnitVTable automount_vtable = {
 
         .dump = automount_dump,
 
-        .active_state = automount_active_state
+        .active_state = automount_active_state,
+        .sub_state_to_string = automount_sub_state_to_string
 };
index a8661bace3332def5359bc410182e93afe07aa74..5f3d9647776e6a10050eac95bf384084f1bb0e3a 100644 (file)
@@ -42,7 +42,7 @@
         "  </method>"                                                   \
         "  <method name=\"ClearJobs\"/>"                                \
         "  <method name=\"ListUnits\">"                                 \
-        "   <arg name=\"units\" type=\"a(ssssouso)\" direction=\"out\"/>" \
+        "   <arg name=\"units\" type=\"a(sssssouso)\" direction=\"out\"/>" \
         "  </method>"                                                   \
         "  <method name=\"ListJobs\">"                                  \
         "   <arg name=\"jobs\" type=\"a(usssoo)\" direction=\"out\"/>"  \
@@ -234,12 +234,12 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
 
                 dbus_message_iter_init_append(reply, &iter);
 
-                if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssssouso)", &sub))
+                if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sssssouso)", &sub))
                         goto oom;
 
                 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
                         char *u_path, *j_path;
-                        const char *id, *description, *load_state, *active_state, *job_type;
+                        const char *id, *description, *load_state, *active_state, *sub_state, *job_type;
                         DBusMessageIter sub2;
                         uint32_t job_id;
 
@@ -253,6 +253,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                         description = unit_description(u);
                         load_state = unit_load_state_to_string(u->meta.load_state);
                         active_state = unit_active_state_to_string(unit_active_state(u));
+                        sub_state = unit_sub_state_to_string(u);
 
                         if (!(u_path = unit_dbus_path(u)))
                                 goto oom;
@@ -276,6 +277,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &description) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &load_state) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &active_state) ||
+                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sub_state) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &job_id) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &job_type) ||
index de5236a64e9a5ff4a1d6b8a889bfd83fe13df912..7897b857b67585b8e01b595be590ddafe3d90cd3 100644 (file)
@@ -49,6 +49,7 @@ static const char introspection[] =
         "  <property name=\"Description\" type=\"s\" access=\"read\"/>"
         "  <property name=\"LoadState\" type=\"s\" access=\"read\"/>"
         "  <property name=\"ActiveState\" type=\"s\" access=\"read\"/>"
+        "  <property name=\"SubState\" type=\"s\" access=\"read\"/>"
         "  <property name=\"FragmentPath\" type=\"s\" access=\"read\"/>"
         "  <property name=\"ActiveEnterTimestamp\" type=\"t\" access=\"read\"/>"
         "  <property name=\"ActiveExitTimestamp\" type=\"t\" access=\"read\"/>"
@@ -113,6 +114,23 @@ static int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const ch
         return 0;
 }
 
+static int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+        Unit *u = data;
+        const char *state;
+
+        assert(m);
+        assert(i);
+        assert(property);
+        assert(u);
+
+        state = unit_sub_state_to_string(u);
+
+        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state))
+                return -ENOMEM;
+
+        return 0;
+}
+
 static int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *property, void *data) {
         Unit *u = data;
         dbus_bool_t b;
@@ -202,6 +220,7 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
                 { "org.freedesktop.systemd1.Unit", "Description",          bus_unit_append_description,  "s",    u                               },
                 { "org.freedesktop.systemd1.Unit", "LoadState",            bus_unit_append_load_state,   "s",    &u->meta.load_state             },
                 { "org.freedesktop.systemd1.Unit", "ActiveState",          bus_unit_append_active_state, "s",    u                               },
+                { "org.freedesktop.systemd1.Unit", "SubState",             bus_unit_append_sub_state,    "s",    u                               },
                 { "org.freedesktop.systemd1.Unit", "FragmentPath",         bus_property_append_string,   "s",    u->meta.fragment_path           },
                 { "org.freedesktop.systemd1.Unit", "ActiveEnterTimestamp", bus_property_append_uint64,   "t",    &u->meta.active_enter_timestamp },
                 { "org.freedesktop.systemd1.Unit", "ActiveExitTimestamp",  bus_property_append_uint64,   "t",    &u->meta.active_exit_timestamp  },
index 0a7c967fabb230d280935d4c3b933b94c1491ea7..b00a0f987f6fb227b7192241e9a2d57f30866dc9 100644 (file)
--- a/device.c
+++ b/device.c
@@ -99,6 +99,12 @@ static UnitActiveState device_active_state(Unit *u) {
         return state_translation_table[DEVICE(u)->state];
 }
 
+static const char *device_sub_state_to_string(Unit *u) {
+        assert(u);
+
+        return state_string_table[DEVICE(u)->state];
+}
+
 static int device_add_escaped_name(Unit *u, const char *dn, bool make_id) {
         char *e;
         int r;
@@ -478,6 +484,7 @@ const UnitVTable device_vtable = {
         .dump = device_dump,
 
         .active_state = device_active_state,
+        .sub_state_to_string = device_sub_state_to_string,
 
         .enumerate = device_enumerate,
         .shutdown = device_shutdown
diff --git a/mount.c b/mount.c
index 04edc6e10fad510722382a28b824029865d3f9c5..d70aaa82186571254ff86de7c61870b5990b01f5 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -720,6 +720,12 @@ static UnitActiveState mount_active_state(Unit *u) {
         return state_translation_table[MOUNT(u)->state];
 }
 
+static const char *mount_sub_state_to_string(Unit *u) {
+        assert(u);
+
+        return state_string_table[MOUNT(u)->state];
+}
+
 static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
         Mount *m = MOUNT(u);
         bool success;
@@ -1286,6 +1292,7 @@ const UnitVTable mount_vtable = {
         .reload = mount_reload,
 
         .active_state = mount_active_state,
+        .sub_state_to_string = mount_sub_state_to_string,
 
         .sigchld_event = mount_sigchld_event,
         .timer_event = mount_timer_event,
index 0a70bb0a7c518168c6d7d01375b0930c10fe34e9..74e8019bd194eddd804bd7aa143bf416c7e5bfec 100644 (file)
--- a/service.c
+++ b/service.c
@@ -1638,6 +1638,12 @@ static UnitActiveState service_active_state(Unit *u) {
         return state_translation_table[SERVICE(u)->state];
 }
 
+static const char *service_sub_state_to_string(Unit *u) {
+        assert(u);
+
+        return service_state_to_string(SERVICE(u)->state);
+}
+
 static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
         Service *s = SERVICE(u);
         bool success;
@@ -2065,6 +2071,7 @@ const UnitVTable service_vtable = {
         .can_reload = service_can_reload,
 
         .active_state = service_active_state,
+        .sub_state_to_string = service_sub_state_to_string,
 
         .sigchld_event = service_sigchld_event,
         .timer_event = service_timer_event,
index 3b74b5e9f82ab15279b7589331d35f44963023ec..4fdd88027a4b9628291743c75fdf11896fabf3a4 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -711,6 +711,12 @@ static UnitActiveState socket_active_state(Unit *u) {
         return state_translation_table[SOCKET(u)->state];
 }
 
+static const char *socket_sub_state_to_string(Unit *u) {
+        assert(u);
+
+        return state_string_table[SOCKET(u)->state];
+}
+
 static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
         Socket *s = SOCKET(u);
 
@@ -894,6 +900,7 @@ const UnitVTable socket_vtable = {
         .stop = socket_stop,
 
         .active_state = socket_active_state,
+        .sub_state_to_string = socket_sub_state_to_string,
 
         .fd_event = socket_fd_event,
         .sigchld_event = socket_sigchld_event,
index 6c01ad1263bd14ece5e17ef39a2ab0b30f53d721..8f16b90482241ece7947281fbb5c500c8e4bbb65 100644 (file)
@@ -104,7 +104,7 @@ int main (string[] args) {
                         uint n = 0;
                         Posix.qsort(list, list.length, sizeof(Manager.UnitInfo), unit_info_compare);
 
-                        stdout.printf("%-45s %-6s %-12s %-17s\n", "UNIT", "LOAD", "ACTIVE", "JOB");
+                        stdout.printf("%-45s %-6s %-12s %-12s %-17s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB");
 
                         foreach (var i in list) {
 
@@ -114,7 +114,7 @@ int main (string[] args) {
                                 if (!all && i.active_state == "inactive")
                                         continue;
 
-                                stdout.printf("%-45s %-6s %-12s", i.id, i.load_state, i.active_state);
+                                stdout.printf("%-45s %-6s %-12s %-12s", i.id, i.load_state, i.active_state, i.sub_state);
 
                                 if (i.job_id != 0)
                                         stdout.printf(" → %-15s", i.job_type);
index 0323c0dbcb11cd898a4975fbec532394bf422594..069c5a1aa275a348654ab7104e031b1c69033b77 100644 (file)
@@ -27,6 +27,7 @@ public interface Manager : DBus.Object {
                 string description;
                 string load_state;
                 string active_state;
+                string sub_state;
                 ObjectPath unit_path;
                 uint32 job_id;
                 string job_type;
index 5c83dbaaf847fd022a28172e0b1e8c7f2b94ffc1..5b897c0bfbc4aef2425473e006448467bd153024 100644 (file)
--- a/target.c
+++ b/target.c
@@ -96,6 +96,12 @@ static UnitActiveState target_active_state(Unit *u) {
         return state_translation_table[TARGET(u)->state];
 }
 
+static const char *target_sub_state_to_string(Unit *u) {
+        assert(u);
+
+        return state_string_table[TARGET(u)->state];
+}
+
 int target_get_runlevel(Target *t) {
 
         static const struct {
@@ -136,5 +142,6 @@ const UnitVTable target_vtable = {
         .start = target_start,
         .stop = target_stop,
 
-        .active_state = target_active_state
+        .active_state = target_active_state,
+        .sub_state_to_string = target_sub_state_to_string
 };
diff --git a/unit.c b/unit.c
index 30ffd9631182d60fb7f2fd331426f8f0329147c6..3b30c8265f579d6330cd854faf1c01d6b6abfd1d 100644 (file)
--- a/unit.c
+++ b/unit.c
@@ -334,6 +334,12 @@ UnitActiveState unit_active_state(Unit *u) {
         return UNIT_VTABLE(u)->active_state(u);
 }
 
+const char* unit_sub_state_to_string(Unit *u) {
+        assert(u);
+
+        return UNIT_VTABLE(u)->sub_state_to_string(u);
+}
+
 static void complete_move(Set **s, Set **other) {
         assert(s);
         assert(other);
diff --git a/unit.h b/unit.h
index ae6e4458adc9d49c245e5877ee9d658ff0de2ec9..052cee01eab93b37473704152a95f8b6150cd360 100644 (file)
--- a/unit.h
+++ b/unit.h
@@ -236,6 +236,12 @@ struct UnitVTable {
          * a simpler one that the engine can understand */
         UnitActiveState (*active_state)(Unit *u);
 
+        /* Returns the substate specific to this unit type as
+         * string. This is purely information so that we can give the
+         * user a more finegrained explanation in which actual state a
+         * unit is in. */
+        const char* (*sub_state_to_string)(Unit *u);
+
         void (*fd_event)(Unit *u, int fd, uint32_t events, Watch *w);
         void (*sigchld_event)(Unit *u, pid_t pid, int code, int status);
         void (*timer_event)(Unit *u, uint64_t n_elapsed, Watch *w);
@@ -320,6 +326,8 @@ bool unit_has_name(Unit *u, const char *name);
 
 UnitActiveState unit_active_state(Unit *u);
 
+const char* unit_sub_state_to_string(Unit *u);
+
 void unit_dump(Unit *u, FILE *f, const char *prefix);
 
 bool unit_can_reload(Unit *u);