pidref: split out pidref_copy() from pidref_dup()
This commit is contained in:
+20
-7
@@ -156,11 +156,11 @@ PidRef *pidref_free(PidRef *pidref) {
|
||||
return mfree(pidref);
|
||||
}
|
||||
|
||||
int pidref_dup(const PidRef *pidref, PidRef **ret) {
|
||||
int pidref_copy(const PidRef *pidref, PidRef *dest) {
|
||||
_cleanup_close_ int dup_fd = -EBADF;
|
||||
pid_t dup_pid = 0;
|
||||
|
||||
assert(ret);
|
||||
assert(dest);
|
||||
|
||||
/* Allocates a new PidRef on the heap, making it a copy of the specified pidref. This does not try to
|
||||
* acquire a pidfd if we don't have one yet!
|
||||
@@ -183,15 +183,28 @@ int pidref_dup(const PidRef *pidref, PidRef **ret) {
|
||||
dup_pid = pidref->pid;
|
||||
}
|
||||
|
||||
PidRef *dup_pidref = new(PidRef, 1);
|
||||
if (!dup_pidref)
|
||||
return -ENOMEM;
|
||||
|
||||
*dup_pidref = (PidRef) {
|
||||
*dest = (PidRef) {
|
||||
.fd = TAKE_FD(dup_fd),
|
||||
.pid = dup_pid,
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pidref_dup(const PidRef *pidref, PidRef **ret) {
|
||||
_cleanup_(pidref_freep) PidRef *dup_pidref = NULL;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
dup_pidref = newdup(PidRef, &PIDREF_NULL, 1);
|
||||
if (!dup_pidref)
|
||||
return -ENOMEM;
|
||||
|
||||
r = pidref_copy(pidref, dup_pidref);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*ret = TAKE_PTR(dup_pidref);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,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_dup(const PidRef *pidref, PidRef **ret);
|
||||
|
||||
int pidref_new_from_pid(pid_t pid, PidRef **ret);
|
||||
|
||||
Reference in New Issue
Block a user