util: minor tweaks to disable_core_dumps()
First, let's rename it to disable_coredumps(), as in the rest of our codebase we spell it "coredump" rather than "core_dump", so let's stick to that. However, also log about failures to turn off core dumpling on LOG_DEBUG, because debug logging is always a good idea.
This commit is contained in:
parent
47cf8ff206
commit
e557b1a655
|
@ -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. */
|
/* Turn off core dumps but only if we're running outside of a container. */
|
||||||
void disable_core_dumps(void) {
|
void disable_coredumps(void) {
|
||||||
if (detect_container() <= 0)
|
int r;
|
||||||
(void) write_string_file("/proc/sys/kernel/core_pattern", "|/bin/false", 0);
|
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,4 +192,4 @@ int version(void);
|
||||||
|
|
||||||
int str_verscmp(const char *s1, const char *s2);
|
int str_verscmp(const char *s1, const char *s2);
|
||||||
|
|
||||||
void disable_core_dumps(void);
|
void disable_coredumps(void);
|
||||||
|
|
|
@ -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
|
/* 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. */
|
* until the systemd-coredump tool is enabled via sysctl. */
|
||||||
if (!skip_setup)
|
if (!skip_setup)
|
||||||
disable_core_dumps();
|
disable_coredumps();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_reexecute(
|
static void do_reexecute(
|
||||||
|
|
|
@ -323,8 +323,7 @@ int main(int argc, char *argv[]) {
|
||||||
if (!in_container)
|
if (!in_container)
|
||||||
sync_with_progress();
|
sync_with_progress();
|
||||||
|
|
||||||
/* Prevent coredumps */
|
disable_coredumps();
|
||||||
disable_core_dumps();
|
|
||||||
|
|
||||||
log_info("Sending SIGTERM to remaining processes...");
|
log_info("Sending SIGTERM to remaining processes...");
|
||||||
broadcast_signal(SIGTERM, true, true);
|
broadcast_signal(SIGTERM, true, true);
|
||||||
|
|
|
@ -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 this is PID 1 disable coredump collection, we'll unlikely be able to process it later on. */
|
||||||
if (is_pid1_crash((const char**) context)) {
|
if (is_pid1_crash((const char**) context)) {
|
||||||
log_notice("Due to PID 1 having crashed coredump collection will now be turned off.");
|
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]);
|
set_iovec_field(iovec, n_iovec, "COREDUMP_UNIT=", context[CONTEXT_UNIT]);
|
||||||
|
|
Loading…
Reference in a new issue