From 387546e5dda4dfbc8d135029239a9570d22f4b04 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Tue, 27 Nov 2018 10:32:42 +0100 Subject: [PATCH] Disable coredump handler for the shutdown period Change-Id: I2e83e006ce0c360616154c68f4871ee221427389 --- src/power/power-handler.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 64484d3..d45267b 100755 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include "dd-deviced.h" @@ -151,6 +152,27 @@ static int disable_systemd_journald(void) return 0; } +/* processes might start to fail abnormally after we kill them via + * umount_partition_by_kill. Failing services can trigger coredump + * handler, which might have trouble handling core in inconsistent + * system state (eg. lack of /opt). Due to this we disable the + * coredump handler for the shutdown period. + */ +static bool disable_coredump_handler(void) +{ + int ret = 0; + int fd = open("/proc/sys/kernel/core_pattern", O_WRONLY); + if (fd >= 0) { + ret = write(fd, "/dev/null", sizeof("/dev/null") - 1); + close(fd); + } + + bool is_ok = fd > 0 && ret > 0; + _I("Disabling core dumps %s", is_ok ? "succeeded" : "failed"); + + return is_ok; +} + /* umount usr data partition */ static void unmount_rw_partition(void) { @@ -171,6 +193,7 @@ static void powerdown(void) disable_display(); disable_systemd_journald(); + disable_coredump_handler(); buf = getenv("PWROFF_DUR"); if (buf != NULL && strlen(buf) < 1024) -- 2.7.4