This new helper takes both a PID and and a pidfd ID, and initializes a
PidRef from it. It ensures they actually belong together and returns an
error if not.
return 0;
}
+int pidref_set_pid_and_pidfd_id(
+ PidRef *pidref,
+ pid_t pid,
+ uint64_t pidfd_id) {
+
+ int r;
+
+ assert(pidref);
+
+ _cleanup_(pidref_done) PidRef n = PIDREF_NULL;
+ r = pidref_set_pid(&n, pid);
+ if (r < 0)
+ return r;
+
+ if (pidfd_id > 0) {
+ pidref_acquire_pidfd_id(&n);
+
+ if (n.fd_id != pidfd_id)
+ return -ESRCH;
+ }
+
+ *pidref = TAKE_PIDREF(n);
+ return 0;
+}
+
int pidref_set_pidstr(PidRef *pidref, const char *pid) {
pid_t nr;
int r;
* PIDREF_MAKE_FROM_PID() above, which does not acquire a pidfd.) */
int pidref_set_pid(PidRef *pidref, pid_t pid);
int pidref_set_pidstr(PidRef *pidref, const char *pid);
+int pidref_set_pid_and_pidfd_id(PidRef *pidref, pid_t pid, uint64_t pidfd_id);
int pidref_set_pidfd(PidRef *pidref, int fd);
int pidref_set_pidfd_take(PidRef *pidref, int fd); /* takes ownership of the passed pidfd on success */
int pidref_set_pidfd_consume(PidRef *pidref, int fd); /* takes ownership of the passed pidfd in both success and failure */