]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pidref: take more fields into account in pidref_compare_func()
authorLennart Poettering <lennart@poettering.net>
Fri, 28 Feb 2025 08:56:02 +0000 (09:56 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 28 Feb 2025 13:18:20 +0000 (14:18 +0100)
src/basic/pidref.c

index ef52cd7a42125c0e1dd613ce92f8b843010dad37..d8c61a17c0f63e38d27b5e03b306b34718dbdadc 100644 (file)
@@ -462,7 +462,31 @@ void pidref_hash_func(const PidRef *pidref, struct siphash *state) {
 }
 
 int pidref_compare_func(const PidRef *a, const PidRef *b) {
-        return CMP(a->pid, b->pid);
+        int r;
+
+        assert(a);
+        assert(b);
+
+        r = CMP(pidref_is_set(a), pidref_is_set(b));
+        if (r != 0)
+                return r;
+
+        r = CMP(pidref_is_automatic(a), pidref_is_automatic(b));
+        if (r != 0)
+                return r;
+
+        r = CMP(pidref_is_remote(a), pidref_is_remote(b));
+        if (r != 0)
+                return r;
+
+        r = CMP(a->pid, b->pid);
+        if (r != 0)
+                return r;
+
+        if (a->fd_id != 0 && b->fd_id != 0)
+                return CMP(a->fd_id, b->fd_id);
+
+        return 0;
 }
 
 DEFINE_HASH_OPS(pidref_hash_ops, PidRef, pidref_hash_func, pidref_compare_func);