process-util: add new FORK_RLIMIT_NOFILE_SAFE flag for safe_fork()

The new flag simply means rlimit_nofile_safe() is called in the child
after all fds are rearranged.
This commit is contained in:
Lennart Poettering
2018-12-01 12:50:45 +01:00
parent 3c069cdac4
commit 909106ebdf
2 changed files with 19 additions and 9 deletions
+9
View File
@@ -35,6 +35,7 @@
#include "missing.h"
#include "process-util.h"
#include "raw-clone.h"
#include "rlimit-util.h"
#include "signal-util.h"
#include "stat-util.h"
#include "string-table.h"
@@ -1401,6 +1402,14 @@ int safe_fork_full(
}
}
if (flags & FORK_RLIMIT_NOFILE_SAFE) {
r = rlimit_nofile_safe();
if (r < 0) {
log_full_errno(prio, r, "Failed to lower RLIMIT_NOFILE's soft limit to 1K: %m");
_exit(EXIT_FAILURE);
}
}
if (ret_pid)
*ret_pid = getpid_cached();