cgroup-util: add cg_read_pidref() helper

Just like cg_read_pid() but returns a PidRef
This commit is contained in:
Lennart Poettering
2023-09-28 23:22:58 +02:00
parent 76dc9e249f
commit 12c7d27b65
2 changed files with 29 additions and 0 deletions
+27
View File
@@ -90,6 +90,33 @@ int cg_read_pid(FILE *f, pid_t *ret) {
return 1;
}
int cg_read_pidref(FILE *f, PidRef *ret) {
int r;
assert(f);
assert(ret);
for (;;) {
pid_t pid;
r = cg_read_pid(f, &pid);
if (r < 0)
return r;
if (r == 0) {
*ret = PIDREF_NULL;
return 0;
}
r = pidref_set_pid(ret, pid);
if (r >= 0)
return 1;
if (r != -ESRCH)
return r;
/* ESRCH → gone by now? just skip over it, read the next */
}
}
int cg_read_event(
const char *controller,
const char *path,