]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-spawn-unix: If a fd is not close-on-exec, look it up in /proc/self/fd
authorSimon McVittie <smcv@collabora.com>
Tue, 20 Nov 2018 17:32:02 +0000 (17:32 +0000)
committerSimon McVittie <smcv@collabora.com>
Tue, 20 Nov 2018 18:56:26 +0000 (18:56 +0000)
In operating systems where /proc/self/fd works like it does on Linux
(Linux itself, and FreeBSD with Linux /proc emulation) this will give
us a clue about the fd that was leaked or opened incorrectly.

Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-spawn-unix.c

index cea5a5f1022e1e4bde906d3acfa09d88cbb2e609..b6a4acd53c73ee1c83a45c0df67bddddc4eda881 100644 (file)
@@ -1063,7 +1063,22 @@ do_exec (int                       child_err_report_fd,
       retval = fcntl (i, F_GETFD);
 
       if (retval != -1 && !(retval & FD_CLOEXEC))
-        _dbus_warn ("Fd %d did not have the close-on-exec flag set!", i);
+        {
+          char description[256] = { 0 };
+          char proc_self_fd[256] = { 0 };
+          size_t description_length = sizeof (description) - 1;
+
+          snprintf (proc_self_fd, sizeof (proc_self_fd) - 1,
+                    "/proc/self/fd/%d", i);
+          proc_self_fd[sizeof (proc_self_fd) - 1] = '\0';
+
+          if (readlink (proc_self_fd, description, description_length) <= 0)
+            snprintf (description, sizeof (description) - 1, "(unknown)");
+
+          description[sizeof (description) - 1] = '\0';
+          _dbus_warn ("Fd %d \"%s\" did not have the close-on-exec flag set!",
+                      i, description);
+        }
     }
 #endif