]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: minor tweaks to disable_core_dumps() 7846/head
authorLennart Poettering <lennart@poettering.net>
Wed, 10 Jan 2018 17:37:54 +0000 (18:37 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 10 Jan 2018 17:44:09 +0000 (18:44 +0100)
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.

src/basic/util.c
src/basic/util.h
src/core/main.c
src/core/shutdown.c
src/coredump/coredump.c

index b1e6f5002efe970c22019bcde62e626d40619b4d..2d31d84165dc55d0e5c0eaf5913c2c45316642ae 100644 (file)
@@ -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");
 }
index c10cfea95233e591b7bb2fe50822374edb450ba5..9d1b10756b29b565d6d1a5b2399aa9563cc22377 100644 (file)
@@ -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);
index ef7d7f58dc4112ad2abe4459a7a4f215da59c8fe..69a98df63c74b428fa6a9dc7eb296e45a9f81df9 100644 (file)
@@ -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(
index b1f581b548293b1d1cb6d4095c88b39e8a694024..ac99211e03d32dcc94f1a830bbf72106704381ac 100644 (file)
@@ -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);
index f83a951df70272bb2c1cfce9079198aa740e19df..fdcea22f5662dabf2e2bb5b4e44ecc39984aebec 100644 (file)
@@ -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]);