chiark / gitweb /
dbus: export unit file state
authorLennart Poettering <lennart@poettering.net>
Sun, 31 Jul 2011 16:28:02 +0000 (18:28 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 31 Jul 2011 16:28:02 +0000 (18:28 +0200)
src/dbus-unit.c
src/dbus-unit.h
src/systemctl.c
src/unit.c
src/unit.h

index bf240f9..b110e33 100644 (file)
@@ -145,6 +145,22 @@ int bus_unit_append_sub_state(DBusMessageIter *i, const char *property, void *da
         return 0;
 }
 
+int bus_unit_append_file_state(DBusMessageIter *i, const char *property, void *data) {
+        Unit *u = data;
+        const char *state;
+
+        assert(i);
+        assert(property);
+        assert(u);
+
+        state = strempty(unit_file_state_to_string(unit_get_unit_file_state(u)));
+
+        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state))
+                return -ENOMEM;
+
+        return 0;
+}
+
 int bus_unit_append_can_start(DBusMessageIter *i, const char *property, void *data) {
         Unit *u = data;
         dbus_bool_t b;
index fc9b4f5..b5c3010 100644 (file)
@@ -85,6 +85,7 @@
         "  <property name=\"ActiveState\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"SubState\" type=\"s\" access=\"read\"/>\n"  \
         "  <property name=\"FragmentPath\" type=\"s\" access=\"read\"/>\n" \
+        "  <property name=\"UnitFileState\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"InactiveExitTimestamp\" type=\"t\" access=\"read\"/>\n" \
         "  <property name=\"InactiveExitTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
         "  <property name=\"ActiveEnterTimestamp\" type=\"t\" access=\"read\"/>\n" \
         { "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", "UnitFileState",        bus_unit_append_file_state,     "s",    u                                 }, \
         { "org.freedesktop.systemd1.Unit", "InactiveExitTimestamp",bus_property_append_usec,       "t",    &u->meta.inactive_exit_timestamp.realtime }, \
         { "org.freedesktop.systemd1.Unit", "InactiveExitTimestampMonotonic",bus_property_append_usec, "t", &u->meta.inactive_exit_timestamp.monotonic }, \
         { "org.freedesktop.systemd1.Unit", "ActiveEnterTimestamp", bus_property_append_usec,       "t",    &u->meta.active_enter_timestamp.realtime }, \
@@ -181,6 +183,7 @@ int bus_unit_append_description(DBusMessageIter *i, const char *property, void *
 int bus_unit_append_load_state(DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_active_state(DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_sub_state(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_file_state(DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_can_start(DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_can_stop(DBusMessageIter *i, const char *property, void *data);
 int bus_unit_append_can_reload(DBusMessageIter *i, const char *property, void *data);
index 3eb8ab5..4981433 100644 (file)
@@ -1962,6 +1962,7 @@ typedef struct UnitStatusInfo {
         const char *load_state;
         const char *active_state;
         const char *sub_state;
+        const char *unit_file_state;
 
         const char *description;
         const char *following;
@@ -2043,6 +2044,8 @@ static void print_status_info(UnitStatusInfo *i) {
 
         if (i->load_error)
                 printf("\t  Loaded: %s%s%s (Reason: %s)\n", on, strna(i->load_state), off, i->load_error);
+        else if (i->path && i->unit_file_state)
+                printf("\t  Loaded: %s%s%s (%s; %s)\n", on, strna(i->load_state), off, i->path, i->unit_file_state);
         else if (i->path)
                 printf("\t  Loaded: %s%s%s (%s)\n", on, strna(i->load_state), off, i->path);
         else
@@ -2285,6 +2288,8 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
                                 i->what = s;
                         else if (streq(name, "Following"))
                                 i->following = s;
+                        else if (streq(name, "UnitFileState"))
+                                i->unit_file_state = s;
                 }
 
                 break;
index d414209..e494834 100644 (file)
@@ -73,6 +73,7 @@ Unit *unit_new(Manager *m) {
         u->meta.type = _UNIT_TYPE_INVALID;
         u->meta.deserialized_job = _JOB_TYPE_INVALID;
         u->meta.default_dependencies = true;
+        u->meta.unit_file_state = _UNIT_FILE_STATE_INVALID;
 
         return u;
 }
@@ -2482,6 +2483,17 @@ int unit_following_set(Unit *u, Set **s) {
         return 0;
 }
 
+UnitFileState unit_get_unit_file_state(Unit *u) {
+        assert(u);
+
+        if (u->meta.unit_file_state < 0 && u->meta.fragment_path)
+                u->meta.unit_file_state = unit_file_get_state(
+                                u->meta.manager->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER,
+                                NULL, file_name_from_path(u->meta.fragment_path));
+
+        return u->meta.unit_file_state;
+}
+
 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_STUB] = "stub",
         [UNIT_LOADED] = "loaded",
index 79f1510..6893b68 100644 (file)
@@ -39,6 +39,7 @@ typedef enum UnitDependency UnitDependency;
 #include "socket-util.h"
 #include "execute.h"
 #include "condition.h"
+#include "install.h"
 
 enum UnitType {
         UNIT_SERVICE = 0,
@@ -192,6 +193,9 @@ struct Meta {
         /* Error code when we didn't manage to load the unit (negative) */
         int load_error;
 
+        /* Cached unit file state */
+        UnitFileState unit_file_state;
+
         /* Garbage collect us we nobody wants or requires us anymore */
         bool stop_when_unneeded;
 
@@ -523,6 +527,8 @@ void unit_trigger_on_failure(Unit *u);
 
 bool unit_condition_test(Unit *u);
 
+UnitFileState unit_get_unit_file_state(Unit *u);
+
 const char *unit_load_state_to_string(UnitLoadState i);
 UnitLoadState unit_load_state_from_string(const char *s);