mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
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:
parent
07336a0672
commit
5ca02bfc39
@ -1254,7 +1254,7 @@ static int status_welcome(void) {
|
|||||||
_cleanup_free_ char *pretty_name = NULL, *ansi_color = NULL;
|
_cleanup_free_ char *pretty_name = NULL, *ansi_color = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (IN_SET(arg_show_status, SHOW_STATUS_NO, SHOW_STATUS_AUTO))
|
if (!show_status_on(arg_show_status))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
r = parse_os_release(NULL,
|
r = parse_os_release(NULL,
|
||||||
|
@ -4083,12 +4083,14 @@ void manager_set_show_status(Manager *m, ShowStatus mode) {
|
|||||||
if (!MANAGER_IS_SYSTEM(m))
|
if (!MANAGER_IS_SYSTEM(m))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m->show_status != mode)
|
bool enabled = show_status_on(mode);
|
||||||
log_debug("%s showing of status.",
|
if (mode != m->show_status)
|
||||||
mode == SHOW_STATUS_NO ? "Disabling" : "Enabling");
|
log_debug("%s showing of status (%s).",
|
||||||
|
enabled ? "Enabling" : "Disabling",
|
||||||
|
strna(show_status_to_string(mode)));
|
||||||
m->show_status = mode;
|
m->show_status = mode;
|
||||||
|
|
||||||
if (IN_SET(mode, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES))
|
if (enabled)
|
||||||
(void) touch("/run/systemd/show-status");
|
(void) touch("/run/systemd/show-status");
|
||||||
else
|
else
|
||||||
(void) unlink("/run/systemd/show-status");
|
(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)
|
if (type != STATUS_TYPE_EMERGENCY && manager_check_ask_password(m) > 0)
|
||||||
return false;
|
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) {
|
const char *manager_get_confirm_spawn(Manager *m) {
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
/* Manager status */
|
/* Manager status */
|
||||||
|
|
||||||
typedef enum ShowStatus {
|
typedef enum ShowStatus {
|
||||||
SHOW_STATUS_NO,
|
SHOW_STATUS_NO, /* printing of status is disabled */
|
||||||
SHOW_STATUS_AUTO,
|
SHOW_STATUS_AUTO, /* disabled but may flip to _TEMPORARY */
|
||||||
SHOW_STATUS_TEMPORARY,
|
SHOW_STATUS_TEMPORARY, /* enabled temporarily, may flip back to _AUTO */
|
||||||
SHOW_STATUS_YES,
|
SHOW_STATUS_YES, /* printing of status is enabled */
|
||||||
_SHOW_STATUS_MAX,
|
_SHOW_STATUS_MAX,
|
||||||
_SHOW_STATUS_INVALID = -1,
|
_SHOW_STATUS_INVALID = -1,
|
||||||
} ShowStatus;
|
} ShowStatus;
|
||||||
@ -28,6 +28,9 @@ typedef enum StatusUnitFormat {
|
|||||||
_STATUS_UNIT_FORMAT_INVALID = -1,
|
_STATUS_UNIT_FORMAT_INVALID = -1,
|
||||||
} StatusUnitFormat;
|
} 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_;
|
ShowStatus show_status_from_string(const char *v) _const_;
|
||||||
const char* show_status_to_string(ShowStatus s) _pure_;
|
const char* show_status_to_string(ShowStatus s) _pure_;
|
||||||
int parse_show_status(const char *v, ShowStatus *ret);
|
int parse_show_status(const char *v, ShowStatus *ret);
|
||||||
|
Loading…
Reference in New Issue
Block a user