]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: limit the LSan shenanigans to PID 1
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 18 Sep 2023 10:34:42 +0000 (12:34 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 18 Sep 2023 11:11:45 +0000 (13:11 +0200)
Addresses https://github.com/systemd/systemd/pull/29194#pullrequestreview-1630530753.
Follow-up to ae5ce7e.

src/core/main.c

index ffdfea8a2e6010b412d67fdaf59148c9d2771517..21582ddd0c5581f058413406b4b44e8062d07d55 100644 (file)
@@ -3185,13 +3185,15 @@ finish:
          * LSan check would not print any actionable information and would just crash
          * PID 1. To make this a bit more helpful, let's try to open /dev/console,
          * and if we succeed redirect LSan's report there. */
+        if (getpid_cached() == 1) {
+                _cleanup_close_ int tty_fd = -EBADF;
 
-        int tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
-        if (tty_fd >= 0)
-            __sanitizer_set_report_fd((void*) (intptr_t) tty_fd);
+                tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
+                if (tty_fd >= 0)
+                        __sanitizer_set_report_fd((void*) (intptr_t) tty_fd);
 
-        __lsan_do_leak_check();
-        tty_fd = safe_close(tty_fd);
+                __lsan_do_leak_check();
+        }
 #endif
 
         if (r < 0)