diff --git a/src/basic/util.c b/src/basic/util.c index b1e6f5002e..2d31d84165 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -618,7 +618,13 @@ int str_verscmp(const char *s1, const char *s2) { } /* Turn off core dumps but only if we're running outside of a container. */ -void disable_core_dumps(void) { - if (detect_container() <= 0) - (void) write_string_file("/proc/sys/kernel/core_pattern", "|/bin/false", 0); +void disable_coredumps(void) { + int r; + + if (detect_container() > 0) + return; + + r = write_string_file("/proc/sys/kernel/core_pattern", "|/bin/false", 0); + if (r < 0) + log_debug_errno(r, "Failed to turn off coredumps, ignoring: %m"); } diff --git a/src/basic/util.h b/src/basic/util.h index c10cfea952..9d1b10756b 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -192,4 +192,4 @@ int version(void); int str_verscmp(const char *s1, const char *s2); -void disable_core_dumps(void); +void disable_coredumps(void); diff --git a/src/core/main.c b/src/core/main.c index ef7d7f58dc..69a98df63c 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1604,7 +1604,7 @@ static void initialize_coredump(bool skip_setup) { /* But at the same time, turn off the core_pattern logic by default, so that no coredumps are stored * until the systemd-coredump tool is enabled via sysctl. */ if (!skip_setup) - disable_core_dumps(); + disable_coredumps(); } static void do_reexecute( diff --git a/src/core/shutdown.c b/src/core/shutdown.c index b1f581b548..ac99211e03 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -323,8 +323,7 @@ int main(int argc, char *argv[]) { if (!in_container) sync_with_progress(); - /* Prevent coredumps */ - disable_core_dumps(); + disable_coredumps(); log_info("Sending SIGTERM to remaining processes..."); broadcast_signal(SIGTERM, true, true); diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index f83a951df7..fdcea22f56 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -1126,7 +1126,7 @@ static int gather_pid_metadata( /* If this is PID 1 disable coredump collection, we'll unlikely be able to process it later on. */ if (is_pid1_crash((const char**) context)) { log_notice("Due to PID 1 having crashed coredump collection will now be turned off."); - disable_core_dumps(); + disable_coredumps(); } set_iovec_field(iovec, n_iovec, "COREDUMP_UNIT=", context[CONTEXT_UNIT]);