process-util: add simple wrapper around PR_SET_CHILD_SUBREAPER

Let's a simple helper that knows how to deal with PID == 1.
This commit is contained in:
Lennart Poettering
2023-06-23 10:05:16 +02:00
parent 2499d32022
commit 8c3fe1b5b5
6 changed files with 28 additions and 9 deletions
+18
View File
@@ -1705,6 +1705,24 @@ int is_reaper_process(void) {
return b != 0;
}
int make_reaper_process(bool b) {
if (getpid_cached() == 1) {
if (!b)
return -EINVAL;
return 0;
}
/* Some prctl()s insist that all 5 arguments are specified, others do not. Let's always specify all,
* to avoid any ambiguities */
if (prctl(PR_SET_CHILD_SUBREAPER, (unsigned long) b, 0UL, 0UL, 0UL) < 0)
return -errno;
return 0;
}
static const char *const sigchld_code_table[] = {
[CLD_EXITED] = "exited",
[CLD_KILLED] = "killed",