Skip to content

Commit c7adcb1

Browse files
committed
core: do not "warn" about mundane emergency actions
For example in a container we'd log: Oct 17 17:01:10 rawhide systemd[1]: Started Power-Off. Oct 17 17:01:10 rawhide systemd[1]: Forcibly powering off: unit succeeded Oct 17 17:01:10 rawhide systemd[1]: Reached target Power-Off. Oct 17 17:01:10 rawhide systemd[1]: Shutting down. and on the console we'd write (in red) [ !! ] Forcibly powering off: unit succeeded This is not useful in any way, and the fact that we're calling an "emergency action" is an internal implementation detail. Let's log about c-a-d and the watchdog actions only.
1 parent a400bd8 commit c7adcb1

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

src/core/emergency-action.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
#include "terminal-util.h"
1313
#include "virt.h"
1414

15-
static void log_and_status(Manager *m, const char *message, const char *reason) {
16-
log_warning("%s: %s", message, reason);
17-
manager_status_printf(m, STATUS_TYPE_EMERGENCY,
18-
ANSI_HIGHLIGHT_RED " !! " ANSI_NORMAL,
19-
"%s: %s", message, reason);
15+
static void log_and_status(Manager *m, bool warn, const char *message, const char *reason) {
16+
log_full(warn ? LOG_WARNING : LOG_DEBUG, "%s: %s", message, reason);
17+
if (warn)
18+
manager_status_printf(m, STATUS_TYPE_EMERGENCY,
19+
ANSI_HIGHLIGHT_RED " !! " ANSI_NORMAL,
20+
"%s: %s", message, reason);
2021
}
2122

2223
int emergency_action(
@@ -38,26 +39,28 @@ int emergency_action(
3839
return -ECANCELED;
3940
}
4041

42+
bool warn = FLAGS_SET(options, EMERGENCY_ACTION_WARN);
43+
4144
switch (action) {
4245

4346
case EMERGENCY_ACTION_REBOOT:
44-
log_and_status(m, "Rebooting", reason);
47+
log_and_status(m, warn, "Rebooting", reason);
4548

4649
(void) update_reboot_parameter_and_warn(reboot_arg);
4750
(void) manager_add_job_by_name_and_warn(m, JOB_START, SPECIAL_REBOOT_TARGET, JOB_REPLACE_IRREVERSIBLY, NULL);
4851

4952
break;
5053

5154
case EMERGENCY_ACTION_REBOOT_FORCE:
52-
log_and_status(m, "Forcibly rebooting", reason);
55+
log_and_status(m, warn, "Forcibly rebooting", reason);
5356

5457
(void) update_reboot_parameter_and_warn(reboot_arg);
5558
m->objective = MANAGER_REBOOT;
5659

5760
break;
5861

5962
case EMERGENCY_ACTION_REBOOT_IMMEDIATE:
60-
log_and_status(m, "Rebooting immediately", reason);
63+
log_and_status(m, warn, "Rebooting immediately", reason);
6164

6265
sync();
6366

@@ -73,7 +76,7 @@ int emergency_action(
7376

7477
case EMERGENCY_ACTION_EXIT:
7578
if (MANAGER_IS_USER(m) || detect_container() > 0) {
76-
log_and_status(m, "Exiting", reason);
79+
log_and_status(m, warn, "Exiting", reason);
7780
(void) manager_add_job_by_name_and_warn(m, JOB_START, SPECIAL_EXIT_TARGET, JOB_REPLACE_IRREVERSIBLY, NULL);
7881
break;
7982
}
@@ -82,13 +85,13 @@ int emergency_action(
8285
_fallthrough_;
8386

8487
case EMERGENCY_ACTION_POWEROFF:
85-
log_and_status(m, "Powering off", reason);
88+
log_and_status(m, warn, "Powering off", reason);
8689
(void) manager_add_job_by_name_and_warn(m, JOB_START, SPECIAL_POWEROFF_TARGET, JOB_REPLACE_IRREVERSIBLY, NULL);
8790
break;
8891

8992
case EMERGENCY_ACTION_EXIT_FORCE:
9093
if (MANAGER_IS_USER(m) || detect_container() > 0) {
91-
log_and_status(m, "Exiting immediately", reason);
94+
log_and_status(m, warn, "Exiting immediately", reason);
9295
m->objective = MANAGER_EXIT;
9396
break;
9497
}
@@ -97,12 +100,12 @@ int emergency_action(
97100
_fallthrough_;
98101

99102
case EMERGENCY_ACTION_POWEROFF_FORCE:
100-
log_and_status(m, "Forcibly powering off", reason);
103+
log_and_status(m, warn, "Forcibly powering off", reason);
101104
m->objective = MANAGER_POWEROFF;
102105
break;
103106

104107
case EMERGENCY_ACTION_POWEROFF_IMMEDIATE:
105-
log_and_status(m, "Powering off immediately", reason);
108+
log_and_status(m, warn, "Powering off immediately", reason);
106109

107110
sync();
108111

src/core/emergency-action.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef enum EmergencyAction {
1818

1919
typedef enum EmergencyActionFlags {
2020
EMERGENCY_ACTION_IS_WATCHDOG = 1 << 0,
21+
EMERGENCY_ACTION_WARN = 1 << 1,
2122
} EmergencyActionFlags;
2223

2324
#include "macro.h"

src/core/job.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,8 @@ static int job_dispatch_timer(sd_event_source *s, uint64_t monotonic, void *user
973973
u = j->unit;
974974
job_finish_and_invalidate(j, JOB_TIMEOUT, true, false);
975975

976-
emergency_action(u->manager, u->job_timeout_action, EMERGENCY_ACTION_IS_WATCHDOG,
976+
emergency_action(u->manager, u->job_timeout_action,
977+
EMERGENCY_ACTION_IS_WATCHDOG|EMERGENCY_ACTION_WARN,
977978
u->job_timeout_reboot_arg, "job timed out");
978979

979980
return 0;

src/core/manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2538,7 +2538,7 @@ static void manager_handle_ctrl_alt_del(Manager *m) {
25382538
if (ratelimit_below(&m->ctrl_alt_del_ratelimit) || m->cad_burst_action == EMERGENCY_ACTION_NONE)
25392539
manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE_IRREVERSIBLY);
25402540
else
2541-
emergency_action(m, m->cad_burst_action, 0, NULL,
2541+
emergency_action(m, m->cad_burst_action, EMERGENCY_ACTION_WARN, NULL,
25422542
"Ctrl-Alt-Del was pressed more than 7 times within 2s");
25432543
}
25442544

src/core/unit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,8 @@ int unit_start_limit_test(Unit *u) {
17241724
log_unit_warning(u, "Start request repeated too quickly.");
17251725
u->start_limit_hit = true;
17261726

1727-
return emergency_action(u->manager, u->start_limit_action, EMERGENCY_ACTION_IS_WATCHDOG,
1727+
return emergency_action(u->manager, u->start_limit_action,
1728+
EMERGENCY_ACTION_IS_WATCHDOG|EMERGENCY_ACTION_WARN,
17281729
u->reboot_arg, "unit failed");
17291730
}
17301731

0 commit comments

Comments
 (0)