process-util: add new FORK_CLOEXEC_OFF flag for disabling O_CLOEXEC on remaining fds

Often the fds that shall stay around in the child shall be passed
to a process over execve(), hence add an option to explicitly disable
O_CLOEXEC on them in the child.
This commit is contained in:
Lennart Poettering
2022-11-04 18:53:36 +01:00
parent ed18c22c98
commit 981cfbe046
2 changed files with 9 additions and 0 deletions
+8
View File
@@ -1372,6 +1372,14 @@ int safe_fork_full(
}
}
if (flags & FORK_CLOEXEC_OFF) {
r = fd_cloexec_many(except_fds, n_except_fds, false);
if (r < 0) {
log_full_errno(prio, r, "Failed to turn off O_CLOEXEC on file descriptors: %m");
_exit(EXIT_FAILURE);
}
}
/* When we were asked to reopen the logs, do so again now */
if (flags & FORK_REOPEN_LOG) {
log_open();