summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-02 02:38:18 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-02 13:23:04 +0100
commitd2dc52dbc45051faa6356213a537081084e9dda4 (patch)
treeb042b6eba6339a42971cf3c1ae27507bbcc202a5 /src/core
parente5035a2778b7ed2a8ac901521ed47cf079359e68 (diff)
systemctl: show unit file preset state in "systemctl status" output"
Diffstat (limited to 'src/core')
-rw-r--r--src/core/dbus-unit.c26
-rw-r--r--src/core/unit.c12
-rw-r--r--src/core/unit.h4
3 files changed, 40 insertions, 2 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index 36b68aee9e..cc09a268c9 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -169,6 +169,29 @@ static int property_get_sub_state(
return sd_bus_message_append(reply, "s", unit_sub_state_to_string(u));
}
+static int property_get_unit_file_preset(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
+ Unit *u = userdata;
+ int r;
+
+ assert(bus);
+ assert(reply);
+ assert(u);
+
+ r = unit_get_unit_file_preset(u);
+
+ return sd_bus_message_append(reply, "s",
+ r < 0 ? "":
+ r > 0 ? "enabled" : "disabled");
+}
+
static int property_get_unit_file_state(
sd_bus *bus,
const char *path,
@@ -184,7 +207,7 @@ static int property_get_unit_file_state(
assert(reply);
assert(u);
- return sd_bus_message_append(reply, "s", unit_file_state_to_string(unit_get_unit_file_state(u)));
+ return sd_bus_message_append(reply, "s", unit_file_state_to_string(unit_get_unit_file_preset(u)));
}
static int property_get_can_start(
@@ -552,6 +575,7 @@ const sd_bus_vtable bus_unit_vtable[] = {
SD_BUS_PROPERTY("SourcePath", "s", NULL, offsetof(Unit, source_path), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("DropInPaths", "as", NULL, offsetof(Unit, dropin_paths), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("UnitFileState", "s", property_get_unit_file_state, 0, 0),
+ SD_BUS_PROPERTY("UnitFilePreset", "s", property_get_unit_file_preset, 0, 0),
BUS_PROPERTY_DUAL_TIMESTAMP("InactiveExitTimestamp", offsetof(Unit, inactive_exit_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
BUS_PROPERTY_DUAL_TIMESTAMP("ActiveEnterTimestamp", offsetof(Unit, active_enter_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
BUS_PROPERTY_DUAL_TIMESTAMP("ActiveExitTimestamp", offsetof(Unit, active_exit_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
diff --git a/src/core/unit.c b/src/core/unit.c
index 9df398ad4e..7daf170e29 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -92,6 +92,7 @@ Unit *unit_new(Manager *m, size_t size) {
u->deserialized_job = _JOB_TYPE_INVALID;
u->default_dependencies = true;
u->unit_file_state = _UNIT_FILE_STATE_INVALID;
+ u->unit_file_preset = -1;
u->on_failure_job_mode = JOB_REPLACE;
return u;
@@ -3090,6 +3091,17 @@ UnitFileState unit_get_unit_file_state(Unit *u) {
return u->unit_file_state;
}
+int unit_get_unit_file_preset(Unit *u) {
+ assert(u);
+
+ if (u->unit_file_preset < 0 && u->fragment_path)
+ u->unit_file_preset = unit_file_query_preset(
+ u->manager->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER,
+ NULL, basename(u->fragment_path));
+
+ return u->unit_file_preset;
+}
+
Unit* unit_ref_set(UnitRef *ref, Unit *u) {
assert(ref);
assert(u);
diff --git a/src/core/unit.h b/src/core/unit.h
index 1b13ca8266..0e45229d7b 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -179,8 +179,9 @@ struct Unit {
/* Error code when we didn't manage to load the unit (negative) */
int load_error;
- /* Cached unit file state */
+ /* Cached unit file state and preset */
UnitFileState unit_file_state;
+ int unit_file_preset;
/* Counterparts in the cgroup filesystem */
char *cgroup_path;
@@ -560,6 +561,7 @@ void unit_start_on_failure(Unit *u);
void unit_trigger_notify(Unit *u);
UnitFileState unit_get_unit_file_state(Unit *u);
+int unit_get_unit_file_preset(Unit *u);
Unit* unit_ref_set(UnitRef *ref, Unit *u);
void unit_ref_unset(UnitRef *ref);