]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredump: shortcut to start backtrace mode
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 8 Oct 2025 15:39:11 +0000 (00:39 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 28 Oct 2025 05:31:37 +0000 (14:31 +0900)
When running as backtrace mode, it is not necessary to use kmsg, not
necessary to disable coredump from the command, and unexpectedly
passed file descriptors can be silently ignored.

src/coredump/coredump-backtrace.c
src/coredump/coredump.c

index 4e223e5220029389687a8d0c29de1149133aa293..4d80cae24c84e0e43be93024f33f7e5b499179c6 100644 (file)
@@ -18,6 +18,7 @@ int coredump_backtrace(int argc, char *argv[]) {
 
         assert(argc >= 2);
 
+        log_setup();
         log_debug("Processing backtrace on stdin...");
 
         iovw = iovw_new();
index 6e110db630c2a2bd08b903206d31e8feb5a0ec61..c29976e281e24479792274618b5382879c4cbcca 100644 (file)
 static int run(int argc, char *argv[]) {
         int r;
 
+        /* When running as backtrace mode, it is not necessary to use kmsg, not necessary to disable coredump
+         * from the command, and unexpectedly passed file descriptors can be silently ignored. */
+        if (streq_ptr(argv[1], "--backtrace"))
+                return coredump_backtrace(argc, argv);
+
         /* First, log to a safe place, since we don't know what crashed and it might
          * be journald which we'd rather not log to then. */
-
         log_set_target_and_open(LOG_TARGET_KMSG);
 
         /* Make sure we never enter a loop */
@@ -25,14 +29,11 @@ static int run(int argc, char *argv[]) {
         if (r < 0)
                 return log_error_errno(r, "Failed to determine the number of file descriptors: %m");
 
-        /* If we got an fd passed, we are running in coredumpd mode. Otherwise we
-         * are invoked from the kernel as coredump handler. */
-        if (r == 0) {
-                if (streq_ptr(argv[1], "--backtrace"))
-                        return coredump_backtrace(argc, argv);
-                else
-                        return coredump_kernel_helper(argc, argv);
-        } else if (r == 1)
+        /* If we got an fd passed, we are running in coredumpd mode. Otherwise we are invoked from the
+         * kernel as coredump handler. */
+        if (r == 0)
+                return coredump_kernel_helper(argc, argv);
+        if (r == 1)
                 return coredump_receive(SD_LISTEN_FDS_START);
 
         return log_error_errno(SYNTHETIC_ERRNO(EINVAL),