X Tutup
Skip to content

Commit 5ca02bf

Browse files
committed
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 systemd#14814.
1 parent 07336a0 commit 5ca02bf

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/core/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ static int status_welcome(void) {
12541254
_cleanup_free_ char *pretty_name = NULL, *ansi_color = NULL;
12551255
int r;
12561256

1257-
if (IN_SET(arg_show_status, SHOW_STATUS_NO, SHOW_STATUS_AUTO))
1257+
if (!show_status_on(arg_show_status))
12581258
return 0;
12591259

12601260
r = parse_os_release(NULL,

src/core/manager.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4083,12 +4083,14 @@ void manager_set_show_status(Manager *m, ShowStatus mode) {
40834083
if (!MANAGER_IS_SYSTEM(m))
40844084
return;
40854085

4086-
if (m->show_status != mode)
4087-
log_debug("%s showing of status.",
4088-
mode == SHOW_STATUS_NO ? "Disabling" : "Enabling");
4086+
bool enabled = show_status_on(mode);
4087+
if (mode != m->show_status)
4088+
log_debug("%s showing of status (%s).",
4089+
enabled ? "Enabling" : "Disabling",
4090+
strna(show_status_to_string(mode)));
40894091
m->show_status = mode;
40904092

4091-
if (IN_SET(mode, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES))
4093+
if (enabled)
40924094
(void) touch("/run/systemd/show-status");
40934095
else
40944096
(void) unlink("/run/systemd/show-status");
@@ -4110,7 +4112,7 @@ static bool manager_get_show_status(Manager *m, StatusType type) {
41104112
if (type != STATUS_TYPE_EMERGENCY && manager_check_ask_password(m) > 0)
41114113
return false;
41124114

4113-
return IN_SET(m->show_status, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES);
4115+
return show_status_on(m->show_status);
41144116
}
41154117

41164118
const char *manager_get_confirm_spawn(Manager *m) {

src/core/show-status.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
/* Manager status */
99

1010
typedef enum ShowStatus {
11-
SHOW_STATUS_NO,
12-
SHOW_STATUS_AUTO,
13-
SHOW_STATUS_TEMPORARY,
14-
SHOW_STATUS_YES,
11+
SHOW_STATUS_NO, /* printing of status is disabled */
12+
SHOW_STATUS_AUTO, /* disabled but may flip to _TEMPORARY */
13+
SHOW_STATUS_TEMPORARY, /* enabled temporarily, may flip back to _AUTO */
14+
SHOW_STATUS_YES, /* printing of status is enabled */
1515
_SHOW_STATUS_MAX,
1616
_SHOW_STATUS_INVALID = -1,
1717
} ShowStatus;
@@ -28,6 +28,9 @@ typedef enum StatusUnitFormat {
2828
_STATUS_UNIT_FORMAT_INVALID = -1,
2929
} StatusUnitFormat;
3030

31+
static inline bool show_status_on(ShowStatus s) {
32+
return IN_SET(s, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES);
33+
}
3134
ShowStatus show_status_from_string(const char *v) _const_;
3235
const char* show_status_to_string(ShowStatus s) _pure_;
3336
int parse_show_status(const char *v, ShowStatus *ret);

0 commit comments

Comments
 (0)
X Tutup