Skip to contentSkip to conversation

shared/fdset: add detailed debug logging to fdset_new_fill()

PATCH Superseded Ashish Kumar Mishra 4 participants 5 messages Mar 10 – Mar 18

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 shared/fdset: add detailed debug logging to fdset_new_fill()

Currently, when fdset_new_fill() fails to open /proc/self/fd or encounters an error while processing individual file descriptors (such as fcntl or fstat failures), it returns a silent error code.

For debugging rarely reproducible failures it becomes difficult to know the exact cause of failure
This commit updates the function to use log_debug_errno() for all error paths and hence provides better visibility into why FD collection failed, including the path of the problematic FD (via fd_get_path) and its inode type.

Upstream-Status: Backport [https://github.com/systemd/systemd/pull/40385]

---
 ...-detailed-debug-logging-to-fdset_new.patch | 97 +++++++++++++++++++
 meta/recipes-core/systemd/systemd_259.3.bb    |  1 +
 2 files changed, 98 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch
meta/recipes-core/systemd/systemd/0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch new file +97 -0
new file mode 100644
index 0000000000..849f5cfda1
@@ -0,0 +1,97 @@
+From 0565f9f27323a8f9e62d85f2add542af99cea06a Mon Sep 17 00:00:00 2001
+From: AshishKumar Mishra <[email protected]>
+Date: Wed, 21 Jan 2026 14:13:29 +0530
+Subject: [PATCH] shared/fdset: add detailed debug logging to fdset_new_fill()
+
+Currently, when fdset_new_fill() fails to open /proc/self/fd or
+encounters an error while processing individual file descriptors
+(such as fcntl or fstat failures), it returns a silent error code.
+
+For debugging rarely reproducible failures it becomes difficult to
+know the exact cause of failure
+This commit updates the function to use log_debug_errno() for all
+error paths and hence  provides better visibility into why FD collection
+failed, including the path of the problematic FD (via fd_get_path)
+and its inode type.
+
+Upstream-Status: Backport [https://github.com/systemd/systemd/pull/40385]
+
+Signed-off-by: AshishKumar Mishra <[email protected]>
+---
+ src/shared/fdset.c | 35 ++++++++++++++++++++++++++---------
+ 1 file changed, 26 insertions(+), 9 deletions(-)
+
+diff --git a/src/shared/fdset.c b/src/shared/fdset.c
+index 832e7fda60..f340f41b0e 100644
+--- a/src/shared/fdset.c
++++ b/src/shared/fdset.c
+@@ -8,6 +8,7 @@
+ #include "alloc-util.h"
+ #include "async.h"
+ #include "dirent-util.h"
++#include "errno-util.h"
+ #include "fd-util.h"
+ #include "fdset.h"
+ #include "log.h"
+@@ -179,9 +180,10 @@ int fdset_new_fill(
+         d = opendir("/proc/self/fd");
+         if (!d) {
+                 if (errno == ENOENT && proc_mounted() == 0)
+-                        return -ENOSYS;
++                        return log_debug_errno(SYNTHETIC_ERRNO(ENOSYS),
++                                               "Failed to open /proc/self/fd/, /proc/ is not mounted.");
+ 
+-                return -errno;
++                return log_debug_errno(errno, "Failed to open /proc/self/fd/: %m ");
+         }
+ 
+         s = fdset_new();
+@@ -210,9 +212,14 @@ int fdset_new_fill(
+                          * been passed in can be collected and fds which have been created locally can be
+                          * ignored, under the assumption that only the latter have O_CLOEXEC set. */
+ 
+-                        fl = fcntl(fd, F_GETFD);
+-                        if (fl < 0)
+-                                return -errno;
++                        fl = RET_NERRNO(fcntl(fd, F_GETFD));
++                        if (fl < 0) {
++                                _cleanup_free_ char *path = NULL;
++                                (void) fd_get_path(fd, &path);
++                                return log_debug_errno(fl,
++                                                       "Failed to get flag of fd=%d (%s): %m ",
++                                                       fd, strna(path));
++                        }
+ 
+                         if (FLAGS_SET(fl, FD_CLOEXEC) != !!filter_cloexec)
+                                 continue;
+@@ -221,13 +228,23 @@ int fdset_new_fill(
+                 /* We need to set CLOEXEC manually only if we're collecting non-CLOEXEC fds. */
+                 if (filter_cloexec <= 0) {
+                         r = fd_cloexec(fd, true);
+-                        if (r < 0)
+-                                return r;
++                        if (r < 0) {
++                                _cleanup_free_ char *path = NULL;
++                                (void) fd_get_path(fd, &path);
++                                return log_debug_errno(r,
++                                                       "Failed to set CLOEXEC flag fd=%d (%s): %m ",
++                                                       fd, strna(path));
++                        }
+                 }
+ 
+                 r = fdset_put(s, fd);
+-                if (r < 0)
+-                        return r;
++                if (r < 0) {
++                        _cleanup_free_ char *path = NULL;
++                        (void) fd_get_path(fd, &path);
++                        return log_debug_errno(r,
++                                               "Failed to put fd=%d (%s) into fdset: %m ",
++                                               fd, strna(path));
++                }
+         }
+ 
+         *ret = TAKE_PTR(s);
+-- 
+2.34.1
+
meta/recipes-core/systemd/systemd_259.3.bb +1 -0
index bcb8fe3d9c..44d319d0c5 100644
@@ -33,6 +33,7 @@ SRC_URI += " \
            file://0001-binfmt-Don-t-install-dependency-links-at-install-tim.patch \
            file://0002-implment-systemd-sysv-install-for-OE.patch \
            file://0003-Do-not-create-var-log-README.patch \
+           file://0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch \
            "
 
 PAM_PLUGINS = " \
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · Ashish Kumar Mishra via lists.openembedded.org

Currently, when fdset_new_fill() fails to open /proc/self/fd or encounters an error while processing individual file descriptors (such as fcntl or fstat failures), it returns a silent error code.

For debugging rarely reproducible failures it becomes difficult to know the exact cause of failure
This commit updates the function to use log_debug_errno() for all error paths and hence provides better visibility into why FD collection failed, including the path of the problematic FD (via fd_get_path) and its inode type.

Quoted 4 lines

Upstream-Status: Backport [https://github.com/systemd/systemd/pull/40385]

---

Hello,

This is the second version of this patch. Please see [0] for how to mark it as such and handle patches iterations (Note the patch changelog below the "---" line). This will make the reviews a lot easier and less confusing for reviewers.

Regards,

[0]: https://docs.yoctoproject.org/contributor-guide/submit-changes.html#taking-patch-review-into-account

Quoted 120 lines
 ...-detailed-debug-logging-to-fdset_new.patch | 97 +++++++++++++++++++
 meta/recipes-core/systemd/systemd_259.3.bb    |  1 +
 2 files changed, 98 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch
meta/recipes-core/systemd/systemd/0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch new file +97 -0
new file mode 100644
index 0000000000..849f5cfda1
@@ -0,0 +1,97 @@
+From 0565f9f27323a8f9e62d85f2add542af99cea06a Mon Sep 17 00:00:00 2001
+From: AshishKumar Mishra <[email protected]>
+Date: Wed, 21 Jan 2026 14:13:29 +0530
+Subject: [PATCH] shared/fdset: add detailed debug logging to fdset_new_fill()
+
+Currently, when fdset_new_fill() fails to open /proc/self/fd or
+encounters an error while processing individual file descriptors
+(such as fcntl or fstat failures), it returns a silent error code.
+
+For debugging rarely reproducible failures it becomes difficult to
+know the exact cause of failure
+This commit updates the function to use log_debug_errno() for all
+error paths and hence  provides better visibility into why FD collection
+failed, including the path of the problematic FD (via fd_get_path)
+and its inode type.
+
+Upstream-Status: Backport [https://github.com/systemd/systemd/pull/40385]
+
+Signed-off-by: AshishKumar Mishra <[email protected]>
+---
+ src/shared/fdset.c | 35 ++++++++++++++++++++++++++---------
+ 1 file changed, 26 insertions(+), 9 deletions(-)
+
+diff --git a/src/shared/fdset.c b/src/shared/fdset.c
+index 832e7fda60..f340f41b0e 100644
+--- a/src/shared/fdset.c
++++ b/src/shared/fdset.c
+@@ -8,6 +8,7 @@
+ #include "alloc-util.h"
+ #include "async.h"
+ #include "dirent-util.h"
++#include "errno-util.h"
+ #include "fd-util.h"
+ #include "fdset.h"
+ #include "log.h"
+@@ -179,9 +180,10 @@ int fdset_new_fill(
+         d = opendir("/proc/self/fd");
+         if (!d) {
+                 if (errno == ENOENT && proc_mounted() == 0)
+-                        return -ENOSYS;
++                        return log_debug_errno(SYNTHETIC_ERRNO(ENOSYS),
++                                               "Failed to open /proc/self/fd/, /proc/ is not mounted.");
+ 
+-                return -errno;
++                return log_debug_errno(errno, "Failed to open /proc/self/fd/: %m ");
+         }
+ 
+         s = fdset_new();
+@@ -210,9 +212,14 @@ int fdset_new_fill(
+                          * been passed in can be collected and fds which have been created locally can be
+                          * ignored, under the assumption that only the latter have O_CLOEXEC set. */
+ 
+-                        fl = fcntl(fd, F_GETFD);
+-                        if (fl < 0)
+-                                return -errno;
++                        fl = RET_NERRNO(fcntl(fd, F_GETFD));
++                        if (fl < 0) {
++                                _cleanup_free_ char *path = NULL;
++                                (void) fd_get_path(fd, &path);
++                                return log_debug_errno(fl,
++                                                       "Failed to get flag of fd=%d (%s): %m ",
++                                                       fd, strna(path));
++                        }
+ 
+                         if (FLAGS_SET(fl, FD_CLOEXEC) != !!filter_cloexec)
+                                 continue;
+@@ -221,13 +228,23 @@ int fdset_new_fill(
+                 /* We need to set CLOEXEC manually only if we're collecting non-CLOEXEC fds. */
+                 if (filter_cloexec <= 0) {
+                         r = fd_cloexec(fd, true);
+-                        if (r < 0)
+-                                return r;
++                        if (r < 0) {
++                                _cleanup_free_ char *path = NULL;
++                                (void) fd_get_path(fd, &path);
++                                return log_debug_errno(r,
++                                                       "Failed to set CLOEXEC flag fd=%d (%s): %m ",
++                                                       fd, strna(path));
++                        }
+                 }
+ 
+                 r = fdset_put(s, fd);
+-                if (r < 0)
+-                        return r;
++                if (r < 0) {
++                        _cleanup_free_ char *path = NULL;
++                        (void) fd_get_path(fd, &path);
++                        return log_debug_errno(r,
++                                               "Failed to put fd=%d (%s) into fdset: %m ",
++                                               fd, strna(path));
++                }
+         }
+ 
+         *ret = TAKE_PTR(s);
+-- 
+2.34.1
+
meta/recipes-core/systemd/systemd_259.3.bb +1 -0
index bcb8fe3d9c..44d319d0c5 100644
@@ -33,6 +33,7 @@ SRC_URI += " \
            file://0001-binfmt-Don-t-install-dependency-links-at-install-tim.patch \
            file://0002-implment-systemd-sysv-install-for-OE.patch \
            file://0003-Do-not-create-var-log-README.patch \
+           file://0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch \
            "
 
 PAM_PLUGINS = " \
Signature · 2 lines
Yoann Congal
Smile ECS
#2 lore raw

Thanks for feedback Yoann
Will reshare by adding the changelog

Thanks,
Ashish

#3 lore raw
In reply to Ashish Kumar Mishra
Quoted 6 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Ashish Kumar Mishra via lists.openembedded.org
Sent: den 10 mars 2026 09:10
To: [email protected]
Cc: Ashish Kumar Mishra <[email protected]>; AshishKumar Mishra <[email protected]>
Subject: [OE-core] [PATCH] shared/fdset: add detailed debug logging to fdset_new_fill()

This changes the systemd recipe, so the commit subject prefix should be "systemd:", e.g.:

systemd: Add detailed debug logging to fdset_new_fill()

Quoted 4 lines

Currently, when fdset_new_fill() fails to open /proc/self/fd or encounters an error while processing individual file descriptors (such as fcntl or fstat failures), it returns a silent error code.

Quoted 8 lines

For debugging rarely reproducible failures it becomes difficult to know the exact cause of failure
This commit updates the function to use log_debug_errno() for all error paths and hence provides better visibility into why FD collection failed, including the path of the problematic FD (via fd_get_path) and its inode type.

Upstream-Status: Backport [https://github.com/systemd/systemd/pull/40385]

The Upstream-Status only go in the patch, not the commit message.

Quoted 27 lines
---
 ...-detailed-debug-logging-to-fdset_new.patch | 97 +++++++++++++++++++
 meta/recipes-core/systemd/systemd_259.3.bb    |  1 +
 2 files changed, 98 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch
meta/recipes-core/systemd/systemd/0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch new file +13 -0
new file mode 100644
index 0000000000..849f5cfda1
@@ -0,0 +1,97 @@
+From 0565f9f27323a8f9e62d85f2add542af99cea06a Mon Sep 17 00:00:00 2001
+From: AshishKumar Mishra <[email protected]>
+Date: Wed, 21 Jan 2026 14:13:29 +0530
+Subject: [PATCH] shared/fdset: add detailed debug logging to fdset_new_fill()
+
+Currently, when fdset_new_fill() fails to open /proc/self/fd or
+encounters an error while processing individual file descriptors
+(such as fcntl or fstat failures), it returns a silent error code.
+
+For debugging rarely reproducible failures it becomes difficult to
+know the exact cause of failure
+This commit updates the function to use log_debug_errno() for all
+error paths and hence  provides better visibility into why FD collection

meta/recipes-core/systemd/systemd/0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch line 23

Quoted 10 lines
meta/recipes-core/systemd/systemd/0018-shared-fdset-add-detailed-debug-logging-to-fdset_new.patch new file +10 -0
+failed, including the path of the problematic FD (via fd_get_path)
+and its inode type.
+
+Upstream-Status: Backport [https://github.com/systemd/systemd/pull/40385]
+
+Signed-off-by: AshishKumar Mishra <[email protected]>
+---
+ src/shared/fdset.c | 35 ++++++++++++++++++++++++++---------
+ 1 file changed, 26 insertions(+), 9 deletions(-)
+

[cut]

//Peter