Disable coredump handler for the shutdown period 00/193900/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 27 Nov 2018 09:32:42 +0000 (10:32 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 27 Nov 2018 09:44:22 +0000 (10:44 +0100)
Change-Id: I2e83e006ce0c360616154c68f4871ee221427389

src/power/power-handler.c

index 64484d3..d45267b 100755 (executable)
@@ -35,6 +35,7 @@
 #include <device-node.h>
 #include <bundle.h>
 #include <eventsystem.h>
+#include <stdbool.h>
 #include <libgdbus/dbus-system.h>
 
 #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)