summaryrefslogtreecommitdiff
path: root/src/systemctl
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-04-13 19:03:43 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-04-14 20:27:59 +0100
commite77e07f60186b96a9b5df398e92a18a72918e0f2 (patch)
treea027c2307414487484f58dea1a1c2752becda4ed /src/systemctl
parent6e4ec79a3cc5a24d9a5ac53c3737c4d398ac383d (diff)
downloadsystemd-e77e07f60186b96a9b5df398e92a18a72918e0f2.tar.gz
preset: Add ignore directive
The ignore directive specifies to not do anything with the given unit and leave existing configuration intact. This allows distributions to gradually adopt preset files by shipping a ignore * preset file.
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl-list-unit-files.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/systemctl/systemctl-list-unit-files.c b/src/systemctl/systemctl-list-unit-files.c
index 4b15e1ca6c..aad248fe1f 100644
--- a/src/systemctl/systemctl-list-unit-files.c
+++ b/src/systemctl/systemctl-list-unit-files.c
@@ -49,6 +49,21 @@ static bool output_show_unit_file(const UnitFileList *u, char **states, char **p
return true;
}
+static const char* preset_action_to_color(PresetAction action, bool underline) {
+ assert(action >= 0);
+
+ switch (action) {
+ case PRESET_ENABLE:
+ return underline ? ansi_highlight_green_underline() : ansi_highlight_green();
+ case PRESET_DISABLE:
+ return underline ? ansi_highlight_red_underline() : ansi_highlight_red();
+ case PRESET_IGNORE:
+ return underline ? ansi_highlight_yellow_underline() : ansi_highlight_yellow();
+ default:
+ return NULL;
+ }
+}
+
static int output_unit_file_list(const UnitFileList *units, unsigned c) {
_cleanup_(table_unrefp) Table *table = NULL;
_cleanup_(unit_file_presets_done) UnitFilePresets presets = {};
@@ -98,22 +113,14 @@ static int output_unit_file_list(const UnitFileList *units, unsigned c) {
return table_log_add_error(r);
if (show_preset_for_state(u->state)) {
- const char *unit_preset_str, *on_preset_color;
+ const char *on_preset_color = underline ? on_underline : ansi_normal();
r = unit_file_query_preset(arg_runtime_scope, arg_root, id, &presets);
- if (r < 0) {
- unit_preset_str = "n/a";
- on_preset_color = underline ? on_underline : ansi_normal();
- } else if (r == 0) {
- unit_preset_str = "disabled";
- on_preset_color = underline ? ansi_highlight_red_underline() : ansi_highlight_red();
- } else {
- unit_preset_str = "enabled";
- on_preset_color = underline ? ansi_highlight_green_underline() : ansi_highlight_green();
- }
+ if (r >= 0)
+ on_preset_color = preset_action_to_color(r, underline);
r = table_add_many(table,
- TABLE_STRING, unit_preset_str,
+ TABLE_STRING, strna(preset_action_past_tense_to_string(r)),
TABLE_SET_BOTH_COLORS, strempty(on_preset_color));
} else
r = table_add_many(table,