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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-03-01 11:42:12 +01:00
parent 07336a0672
commit 5ca02bfc39
3 changed files with 15 additions and 10 deletions
+7 -5
View File
@@ -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) {