]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pidref: copy fd id in pidref_copy() too
authorLennart Poettering <lennart@poettering.net>
Wed, 8 Jan 2025 09:53:00 +0000 (10:53 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 8 Jan 2025 13:51:19 +0000 (14:51 +0100)
src/basic/pidref.c
src/basic/pidref.h

index f665438375be36a87b28e6e9ba47e5719a645313..53992aa3800f30e5232a25ee72a33d2a0cf40c98 100644 (file)
@@ -219,37 +219,32 @@ PidRef* pidref_free(PidRef *pidref) {
         return mfree(pidref);
 }
 
-int pidref_copy(const PidRef *pidref, PidRef *dest) {
-        _cleanup_close_ int dup_fd = -EBADF;
-        pid_t dup_pid = 0;
+int pidref_copy(const PidRef *pidref, PidRef *ret) {
+        _cleanup_(pidref_done) PidRef copy = PIDREF_NULL;
 
         /* If NULL is passed we'll generate a PidRef that refers to no process. This makes it easy to
          * copy pidref fields that might or might not reference a process yet. */
 
-        assert(dest);
+        assert(ret);
 
         if (pidref) {
                 if (pidref_is_remote(pidref)) /* Propagate remote flag */
-                        dup_fd = -EREMOTE;
+                        copy.fd = -EREMOTE;
                 else if (pidref->fd >= 0) {
-                        dup_fd = fcntl(pidref->fd, F_DUPFD_CLOEXEC, 3);
-                        if (dup_fd < 0) {
+                        copy.fd = fcntl(pidref->fd, F_DUPFD_CLOEXEC, 3);
+                        if (copy.fd < 0) {
                                 if (!ERRNO_IS_RESOURCE(errno))
                                         return -errno;
 
-                                dup_fd = -EBADF;
+                                copy.fd = -EBADF;
                         }
                 }
 
-                if (pidref->pid > 0)
-                        dup_pid = pidref->pid;
+                copy.pid = pidref->pid;
+                copy.fd_id = pidref->fd_id;
         }
 
-        *dest = (PidRef) {
-                .fd = TAKE_FD(dup_fd),
-                .pid = dup_pid,
-        };
-
+        *ret = TAKE_PIDREF(copy);
         return 0;
 }
 
index 42ddf4e50bcd963b0b474ff8e21acb4b6ae3d2f6..a268af46037269bab4691eceb8ebd9026df76cbf 100644 (file)
@@ -83,7 +83,7 @@ void pidref_done(PidRef *pidref);
 PidRef* pidref_free(PidRef *pidref);
 DEFINE_TRIVIAL_CLEANUP_FUNC(PidRef*, pidref_free);
 
-int pidref_copy(const PidRef *pidref, PidRef *dest);
+int pidref_copy(const PidRef *pidref, PidRef *ret);
 int pidref_dup(const PidRef *pidref, PidRef **ret);
 
 int pidref_new_from_pid(pid_t pid, PidRef **ret);