diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-02-28 22:49:19 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-01 11:42:12 +0100 |
commit | 5ca02bfc39685ffa62aa46533f951bd8ede89082 (patch) | |
tree | c72384aa4ce86dbf51277da7438aa1f4c0bac8a1 /src | |
parent | 07336a067216f3e5d7551b090c5972c120805d0e (diff) | |
download | systemd-5ca02bfc39685ffa62aa46533f951bd8ede89082.tar.gz |
core: fix message about show status state
We would say "Enabling" also for SHOW_STATUS_AUTO, which is actually
"soft off". So just print the exact state to make things easier to understand.
Also add a helper function to avoid repeating the enum value list.
For #14814.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/main.c | 2 | ||||
-rw-r--r-- | src/core/manager.c | 12 | ||||
-rw-r--r-- | src/core/show-status.h | 11 |
3 files changed, 15 insertions, 10 deletions
diff --git a/src/core/main.c b/src/core/main.c index 23a8ada1ec..09846eaadb 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1254,7 +1254,7 @@ static int status_welcome(void) { _cleanup_free_ char *pretty_name = NULL, *ansi_color = NULL; int r; - if (IN_SET(arg_show_status, SHOW_STATUS_NO, SHOW_STATUS_AUTO)) + if (!show_status_on(arg_show_status)) return 0; r = parse_os_release(NULL, diff --git a/src/core/manager.c b/src/core/manager.c index a5290eba0c..7ccfde1567 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -4083,12 +4083,14 @@ void manager_set_show_status(Manager *m, ShowStatus mode) { if (!MANAGER_IS_SYSTEM(m)) return; - if (m->show_status != mode) - log_debug("%s showing of status.", - mode == SHOW_STATUS_NO ? "Disabling" : "Enabling"); + bool enabled = show_status_on(mode); + if (mode != m->show_status) + log_debug("%s showing of status (%s).", + enabled ? "Enabling" : "Disabling", + strna(show_status_to_string(mode))); m->show_status = mode; - if (IN_SET(mode, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES)) + if (enabled) (void) touch("/run/systemd/show-status"); else (void) unlink("/run/systemd/show-status"); @@ -4110,7 +4112,7 @@ static bool manager_get_show_status(Manager *m, StatusType type) { if (type != STATUS_TYPE_EMERGENCY && manager_check_ask_password(m) > 0) return false; - return IN_SET(m->show_status, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES); + return show_status_on(m->show_status); } const char *manager_get_confirm_spawn(Manager *m) { diff --git a/src/core/show-status.h b/src/core/show-status.h index 247caec77c..0686b60d74 100644 --- a/src/core/show-status.h +++ b/src/core/show-status.h @@ -8,10 +8,10 @@ /* Manager status */ typedef enum ShowStatus { - SHOW_STATUS_NO, - SHOW_STATUS_AUTO, - SHOW_STATUS_TEMPORARY, - SHOW_STATUS_YES, + SHOW_STATUS_NO, /* printing of status is disabled */ + SHOW_STATUS_AUTO, /* disabled but may flip to _TEMPORARY */ + SHOW_STATUS_TEMPORARY, /* enabled temporarily, may flip back to _AUTO */ + SHOW_STATUS_YES, /* printing of status is enabled */ _SHOW_STATUS_MAX, _SHOW_STATUS_INVALID = -1, } ShowStatus; @@ -28,6 +28,9 @@ typedef enum StatusUnitFormat { _STATUS_UNIT_FORMAT_INVALID = -1, } StatusUnitFormat; +static inline bool show_status_on(ShowStatus s) { + return IN_SET(s, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES); +} ShowStatus show_status_from_string(const char *v) _const_; const char* show_status_to_string(ShowStatus s) _pure_; int parse_show_status(const char *v, ShowStatus *ret); |