summaryrefslogtreecommitdiffstats
path: root/src/shutdown
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-04-11 18:58:43 +0200
committerGitHub <noreply@github.com>2019-04-11 18:58:43 +0200
commitaa46c28418c3111df9b9341d8796c16e0d40261c (patch)
treed1c566119a064cd1d4c1599dfabcff97472d7740 /src/shutdown
parentMerge pull request #12226 from poettering/22bit-pids (diff)
parentcore/killall: Add documentation about broadcast_signal() (diff)
downloadsystemd-aa46c28418c3111df9b9341d8796c16e0d40261c.tar.xz
systemd-aa46c28418c3111df9b9341d8796c16e0d40261c.zip
Merge pull request #12153 from benjarobin/killall-show-not-killed
shutdown/killall: Show in the console the processes not yet killed
Diffstat (limited to 'src/shutdown')
-rw-r--r--src/shutdown/shutdown.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c
index 842ba57f13..25a538df50 100644
--- a/src/shutdown/shutdown.c
+++ b/src/shutdown/shutdown.c
@@ -32,6 +32,7 @@
#include "signal-util.h"
#include "string-util.h"
#include "switch-root.h"
+#include "sysctl-util.h"
#include "terminal-util.h"
#include "umount.h"
#include "util.h"
@@ -255,6 +256,42 @@ static void sync_with_progress(void) {
(void) kill(pid, SIGKILL);
}
+static int read_current_sysctl_printk_log_level(void) {
+ _cleanup_free_ char *sysctl_printk_vals = NULL, *sysctl_printk_curr = NULL;
+ unsigned current_lvl = 0;
+ const char *p;
+ int r;
+
+ r = sysctl_read("kernel/printk", &sysctl_printk_vals);
+ if (r < 0)
+ return log_debug_errno(r, "Cannot read sysctl kernel.printk: %m");
+
+ p = sysctl_printk_vals;
+ r = extract_first_word(&p, &sysctl_printk_curr, NULL, 0);
+ if (r > 0)
+ r = safe_atou(sysctl_printk_curr, &current_lvl);
+ else if (r == 0)
+ r = -EINVAL;
+
+ if (r < 0)
+ return log_debug_errno(r, "Unexpected sysctl kernel.printk content: %s", sysctl_printk_vals);
+
+ return current_lvl;
+}
+
+static void bump_sysctl_printk_log_level(int min_level) {
+ /* Set the logging level to be able to see messages with log level smaller or equal to min_level */
+
+ int current_lvl = read_current_sysctl_printk_log_level();
+ if (current_lvl >= 0 && current_lvl <= min_level) {
+ char buf[DECIMAL_STR_MAX(int)];
+ xsprintf(buf, "%d", min_level + 1);
+ int r = sysctl_write("kernel/printk", buf);
+ if (r < 0)
+ log_debug_errno(r, "Failed to bump kernel.printk to %s: %m", buf);
+ }
+}
+
int main(int argc, char *argv[]) {
bool need_umount, need_swapoff, need_loop_detach, need_dm_detach;
bool in_container, use_watchdog = false, can_initrd;
@@ -305,6 +342,16 @@ int main(int argc, char *argv[]) {
(void) cg_get_root_path(&cgroup);
in_container = detect_container() > 0;
+ /* If the logging messages are going to KMSG, and if we are not running from a container,
+ * then try to update the sysctl kernel.printk current value in order to see "info" messages;
+ * This current log level is not updated if already big enough.
+ */
+ if (!in_container && IN_SET(log_get_target(), LOG_TARGET_AUTO,
+ LOG_TARGET_JOURNAL_OR_KMSG,
+ LOG_TARGET_SYSLOG_OR_KMSG,
+ LOG_TARGET_KMSG))
+ bump_sysctl_printk_log_level(LOG_INFO);
+
use_watchdog = getenv("WATCHDOG_USEC");
watchdog_device = getenv("WATCHDOG_DEVICE");
if (watchdog_device) {