process-util: add new helper pidref_get_ppid_as_pidref()

This commit is contained in:
Lennart Poettering
2025-01-10 14:14:17 +01:00
parent 8c0da3af28
commit 9237a63a80
3 changed files with 62 additions and 0 deletions
+23
View File
@@ -848,6 +848,29 @@ TEST(pid_get_ppid) {
pid = ppid;
}
/* the same via pidref */
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
ASSERT_OK(pidref_set_self(&pidref));
for (;;) {
_cleanup_free_ char *c1 = NULL, *c2 = NULL;
_cleanup_(pidref_done) PidRef parent = PIDREF_NULL;
r = pidref_get_ppid_as_pidref(&pidref, &parent);
if (r == -EADDRNOTAVAIL) {
log_info("No further parent PID");
break;
}
ASSERT_OK(r);
ASSERT_OK(pidref_get_cmdline(&pidref, SIZE_MAX, PROCESS_CMDLINE_COMM_FALLBACK, &c1));
ASSERT_OK(pidref_get_cmdline(&parent, SIZE_MAX, PROCESS_CMDLINE_COMM_FALLBACK, &c2));
log_info("Parent of " PID_FMT " (%s) is " PID_FMT " (%s).", pidref.pid, c1, parent.pid, c2);
pidref_done(&pidref);
pidref = TAKE_PIDREF(parent);
}
}
TEST(set_oom_score_adjust) {