summaryrefslogtreecommitdiff
path: root/src/core/emergency-action.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-10-17 17:27:20 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-10-17 19:32:09 +0200
commitc7adcb1af9946d0672c16bb4bb7eedf39b3d1fcb (patch)
tree385536c6cf55f636616a879c8ce7913860d3002b /src/core/emergency-action.c
parenta400bd8c2a6285576edf8e2147e1d17aab129501 (diff)
downloadsystemd-c7adcb1af9946d0672c16bb4bb7eedf39b3d1fcb.tar.gz
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.
Diffstat (limited to 'src/core/emergency-action.c')
-rw-r--r--src/core/emergency-action.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/core/emergency-action.c b/src/core/emergency-action.c
index e12ff81601..c91d2bf5ff 100644
--- a/src/core/emergency-action.c
+++ b/src/core/emergency-action.c
@@ -12,11 +12,12 @@
#include "terminal-util.h"
#include "virt.h"
-static void log_and_status(Manager *m, const char *message, const char *reason) {
- log_warning("%s: %s", message, reason);
- manager_status_printf(m, STATUS_TYPE_EMERGENCY,
- ANSI_HIGHLIGHT_RED " !! " ANSI_NORMAL,
- "%s: %s", message, reason);
+static void log_and_status(Manager *m, bool warn, const char *message, const char *reason) {
+ log_full(warn ? LOG_WARNING : LOG_DEBUG, "%s: %s", message, reason);
+ if (warn)
+ manager_status_printf(m, STATUS_TYPE_EMERGENCY,
+ ANSI_HIGHLIGHT_RED " !! " ANSI_NORMAL,
+ "%s: %s", message, reason);
}
int emergency_action(
@@ -38,10 +39,12 @@ int emergency_action(
return -ECANCELED;
}
+ bool warn = FLAGS_SET(options, EMERGENCY_ACTION_WARN);
+
switch (action) {
case EMERGENCY_ACTION_REBOOT:
- log_and_status(m, "Rebooting", reason);
+ log_and_status(m, warn, "Rebooting", reason);
(void) update_reboot_parameter_and_warn(reboot_arg);
(void) manager_add_job_by_name_and_warn(m, JOB_START, SPECIAL_REBOOT_TARGET, JOB_REPLACE_IRREVERSIBLY, NULL);
@@ -49,7 +52,7 @@ int emergency_action(
break;
case EMERGENCY_ACTION_REBOOT_FORCE:
- log_and_status(m, "Forcibly rebooting", reason);
+ log_and_status(m, warn, "Forcibly rebooting", reason);
(void) update_reboot_parameter_and_warn(reboot_arg);
m->objective = MANAGER_REBOOT;
@@ -57,7 +60,7 @@ int emergency_action(
break;
case EMERGENCY_ACTION_REBOOT_IMMEDIATE:
- log_and_status(m, "Rebooting immediately", reason);
+ log_and_status(m, warn, "Rebooting immediately", reason);
sync();
@@ -73,7 +76,7 @@ int emergency_action(
case EMERGENCY_ACTION_EXIT:
if (MANAGER_IS_USER(m) || detect_container() > 0) {
- log_and_status(m, "Exiting", reason);
+ log_and_status(m, warn, "Exiting", reason);
(void) manager_add_job_by_name_and_warn(m, JOB_START, SPECIAL_EXIT_TARGET, JOB_REPLACE_IRREVERSIBLY, NULL);
break;
}
@@ -82,13 +85,13 @@ int emergency_action(
_fallthrough_;
case EMERGENCY_ACTION_POWEROFF:
- log_and_status(m, "Powering off", reason);
+ log_and_status(m, warn, "Powering off", reason);
(void) manager_add_job_by_name_and_warn(m, JOB_START, SPECIAL_POWEROFF_TARGET, JOB_REPLACE_IRREVERSIBLY, NULL);
break;
case EMERGENCY_ACTION_EXIT_FORCE:
if (MANAGER_IS_USER(m) || detect_container() > 0) {
- log_and_status(m, "Exiting immediately", reason);
+ log_and_status(m, warn, "Exiting immediately", reason);
m->objective = MANAGER_EXIT;
break;
}
@@ -97,12 +100,12 @@ int emergency_action(
_fallthrough_;
case EMERGENCY_ACTION_POWEROFF_FORCE:
- log_and_status(m, "Forcibly powering off", reason);
+ log_and_status(m, warn, "Forcibly powering off", reason);
m->objective = MANAGER_POWEROFF;
break;
case EMERGENCY_ACTION_POWEROFF_IMMEDIATE:
- log_and_status(m, "Powering off immediately", reason);
+ log_and_status(m, warn, "Powering off immediately", reason);
sync();