From e8783d7620e4811738be078480aa5ffc9bbdcf9b Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Wed, 12 Apr 2023 21:07:29 +0200
Subject: [PATCH] pid1: add some debug logging when stashing ds into the
 fdstore

Conflict:Context Adaptation. Log Adaptation.
Reference:https://github.com/systemd/systemd/commit/e8783d7620e4811738be078480aa5ffc9bbdcf9b

---
 src/core/service.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/core/service.c b/src/core/service.c
index a7d5f3f..103c8a5 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -427,6 +427,7 @@ static int on_fd_store_io(sd_event_source *e, int fd, uint32_t revents, void *us
 }
 
 static int service_add_fd_store(Service *s, int fd, const char *name, bool do_poll) {
+        struct stat st;
         ServiceFDStore *fs;
         int r;
 
@@ -435,16 +436,22 @@ static int service_add_fd_store(Service *s, int fd, const char *name, bool do_po
         assert(s);
         assert(fd >= 0);
 
+        if (fstat(fd, &st) < 0)
+                return -errno;
+
+        log_unit_debug(UNIT(s), "Trying to stash fd for dev=" "%u:%u" "/inode=%" PRIu64, major(st.st_dev), minor(st.st_dev), (uint64_t) st.st_ino);
+
         if (s->n_fd_store >= s->n_fd_store_max)
-                return -EXFULL; /* Our store is full.
-                                 * Use this errno rather than E[NM]FILE to distinguish from
-                                 * the case where systemd itself hits the file limit. */
+                /* Our store is full.  Use this errno rather than E[NM]FILE to distinguish from the case
+                 * where systemd itself hits the file limit. */
+                return log_unit_debug_errno(UNIT(s), SYNTHETIC_ERRNO(EXFULL), "Hit fd store limit.");
 
         LIST_FOREACH(fd_store, fs, s->fd_store) {
                 r = same_fd(fs->fd, fd);
                 if (r < 0)
                         return r;
                 if (r > 0) {
+                        log_unit_debug(UNIT(s), "Suppressing duplicate fd in fd store.");
                         asynchronous_close(fd);
                         return 0; /* fd already included */
                 }
-- 
2.33.0

