summaryrefslogtreecommitdiff
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
parente5035a2778b7ed2a8ac901521ed47cf079359e68 (diff)
systemctl: show unit file preset state in "systemctl status" output"
-rw-r--r--src/core/dbus-unit.c26
-rw-r--r--src/core/unit.c12
-rw-r--r--src/core/unit.h4
-rw-r--r--src/systemctl/systemctl.c8
4 files changed, 47 insertions, 3 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);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3f5bcdd1fb..74af772794 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3221,6 +3221,7 @@ typedef struct UnitStatusInfo {
const char *active_state;
const char *sub_state;
const char *unit_file_state;
+ const char *unit_file_preset;
const char *description;
const char *following;
@@ -3344,7 +3345,10 @@ static void print_status_info(
if (i->load_error)
printf(" Loaded: %s%s%s (Reason: %s)\n",
on, strna(i->load_state), off, i->load_error);
- else if (path && i->unit_file_state)
+ else if (path && !isempty(i->unit_file_state) && !isempty(i->unit_file_preset))
+ printf(" Loaded: %s%s%s (%s; %s; vendor preset: %s)\n",
+ on, strna(i->load_state), off, path, i->unit_file_state, i->unit_file_preset);
+ else if (path && !isempty(i->unit_file_state))
printf(" Loaded: %s%s%s (%s; %s)\n",
on, strna(i->load_state), off, path, i->unit_file_state);
else if (path)
@@ -3669,6 +3673,8 @@ static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *
i->following = s;
else if (streq(name, "UnitFileState"))
i->unit_file_state = s;
+ else if (streq(name, "UnitFilePreset"))
+ i->unit_file_preset = s;
else if (streq(name, "Result"))
i->result = s;
}