diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dbus-unit.c | 16 | ||||
-rw-r--r-- | src/dbus-unit.h | 3 | ||||
-rw-r--r-- | src/systemctl.c | 5 | ||||
-rw-r--r-- | src/unit.c | 12 | ||||
-rw-r--r-- | src/unit.h | 6 |
5 files changed, 42 insertions, 0 deletions
diff --git a/src/dbus-unit.c b/src/dbus-unit.c index bf240f97d4..b110e33174 100644 --- a/src/dbus-unit.c +++ b/src/dbus-unit.c @@ -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; diff --git a/src/dbus-unit.h b/src/dbus-unit.h index fc9b4f5768..b5c3010728 100644 --- a/src/dbus-unit.h +++ b/src/dbus-unit.h @@ -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" \ @@ -144,6 +145,7 @@ { "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); diff --git a/src/systemctl.c b/src/systemctl.c index 3eb8ab5b5c..4981433ebe 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -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; diff --git a/src/unit.c b/src/unit.c index d4142098d1..e494834a61 100644 --- a/src/unit.c +++ b/src/unit.c @@ -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", diff --git a/src/unit.h b/src/unit.h index 79f15103ba..6893b689a9 100644 --- a/src/unit.h +++ b/src/unit.h @@ -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); |