summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-05-22 13:27:36 +0200
committerMike Yuan <me@yhndnzj.com>2024-06-14 16:46:03 +0200
commit1b6239632dd9697c435d5862a9e2417ee990c6c0 (patch)
tree33cd13606654fe11b77ccc60ea1e4186d4640936 /src
parentiovec-util: add exported constant empty but valid (i.e. non-NULL) iovec (diff)
downloadsystemd-1b6239632dd9697c435d5862a9e2417ee990c6c0.tar.xz
systemd-1b6239632dd9697c435d5862a9e2417ee990c6c0.zip
pidref: introduce pidfd_inode_ids_supported helper
Also, correct the comment about pidfs (added in kernel 6.9 rather than 6.8). Co-authored-by: Lennart Poettering <lennart@poettering.net>
Diffstat (limited to 'src')
-rw-r--r--src/basic/pidref.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/basic/pidref.c b/src/basic/pidref.c
index 69a010210d..11abadff82 100644
--- a/src/basic/pidref.c
+++ b/src/basic/pidref.c
@@ -6,6 +6,7 @@
#include "errno-util.h"
#include "fd-util.h"
+#include "missing_magic.h"
#include "missing_syscall.h"
#include "missing_wait.h"
#include "parse-util.h"
@@ -14,6 +15,23 @@
#include "signal-util.h"
#include "stat-util.h"
+static int pidfd_inode_ids_supported(void) {
+ static int cached = -1;
+
+ if (cached >= 0)
+ return cached;
+
+ _cleanup_close_ int fd = pidfd_open(getpid_cached(), 0);
+ if (fd < 0) {
+ if (ERRNO_IS_NOT_SUPPORTED(errno))
+ return (cached = false);
+
+ return -errno;
+ }
+
+ return (cached = fd_is_fs_type(fd, PID_FS_MAGIC));
+}
+
bool pidref_equal(const PidRef *a, const PidRef *b) {
int r;
@@ -28,8 +46,11 @@ bool pidref_equal(const PidRef *a, const PidRef *b) {
return true;
/* pidfds live in their own pidfs and each process comes with a unique inode number since
- * kernel 6.8. We can safely do this on older kernels too though, as previously anonymous
- * inode was used and inode number was the same for all pidfds. */
+ * kernel 6.9. */
+
+ if (pidfd_inode_ids_supported() <= 0)
+ return true;
+
r = fd_inode_same(a->fd, b->fd);
if (r < 0)
log_debug_errno(r, "Failed to check whether pidfds for pid " PID_FMT " are equal, assuming yes: %m",