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 bf240f97d45cc5bb1bd86bcc910fdf45ac36d0a7..b110e3317459119e1cefab466dc11257c5c04706 100644 (file)
@@ -145,6 +145,22 @@ int bus_unit_append_sub_state(DBusMessageIter *i, const char *property, void *da
         return 0;
 }
 
         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;
 int bus_unit_append_can_start(DBusMessageIter *i, const char *property, void *data) {
         Unit *u = data;
         dbus_bool_t b;
index fc9b4f5768bbf400e0c64d02df0b35b7d65e3a36..b5c3010728cec37274818959751a1925833d1587 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=\"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" \
         "  <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", "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 }, \
         { "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_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);
 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 3eb8ab5b5cd78240e33a112e392a64985964d23c..4981433ebefa367008575235fb97cc7951b48100 100644 (file)
@@ -1962,6 +1962,7 @@ typedef struct UnitStatusInfo {
         const char *load_state;
         const char *active_state;
         const char *sub_state;
         const char *load_state;
         const char *active_state;
         const char *sub_state;
+        const char *unit_file_state;
 
         const char *description;
         const char *following;
 
         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);
 
         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
         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;
                                 i->what = s;
                         else if (streq(name, "Following"))
                                 i->following = s;
+                        else if (streq(name, "UnitFileState"))
+                                i->unit_file_state = s;
                 }
 
                 break;
                 }
 
                 break;
index d4142098d1f4b742ca357f17aec42824d3efa61d..e494834a6151d7afc9f062ee0f40662b0ada9fa7 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.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;
 }
 
         return u;
 }
@@ -2482,6 +2483,17 @@ int unit_following_set(Unit *u, Set **s) {
         return 0;
 }
 
         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",
 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_STUB] = "stub",
         [UNIT_LOADED] = "loaded",
index 79f15103baaf65cba3c1db22ebf9c1495d27927f..6893b689a925b51b583c1c7198e8031411103ad5 100644 (file)
@@ -39,6 +39,7 @@ typedef enum UnitDependency UnitDependency;
 #include "socket-util.h"
 #include "execute.h"
 #include "condition.h"
 #include "socket-util.h"
 #include "execute.h"
 #include "condition.h"
+#include "install.h"
 
 enum UnitType {
         UNIT_SERVICE = 0,
 
 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;
 
         /* 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;
 
         /* 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);
 
 
 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);
 
 const char *unit_load_state_to_string(UnitLoadState i);
 UnitLoadState unit_load_state_from_string(const char *s);