main: split out reading of /proc/sys/fs/nr_open into its own function

This doesn't really reduce the code size over all, but it does make main.c
shorter and more readable, and that's always a good thing.
This commit is contained in:
Lennart Poettering
2018-06-06 14:39:15 +02:00
parent 0e37c169fb
commit 9264cc39ce
4 changed files with 38 additions and 15 deletions
+4 -15
View File
@@ -1136,10 +1136,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching
}
static int bump_rlimit_nofile(struct rlimit *saved_rlimit) {
struct rlimit nl;
int r;
int min_max;
_cleanup_free_ char *nr_open = NULL;
int r, nr;
assert(saved_rlimit);
@@ -1160,17 +1157,9 @@ static int bump_rlimit_nofile(struct rlimit *saved_rlimit) {
arg_default_rlimit[RLIMIT_NOFILE] = rl;
}
/* Get current RLIMIT_NOFILE maximum compiled into the kernel. */
r = read_one_line_file("/proc/sys/fs/nr_open", &nr_open);
if (r >= 0)
r = safe_atoi(nr_open, &min_max);
/* If we fail, fallback to the hard-coded kernel limit of 1024 * 1024. */
if (r < 0)
min_max = 1024 * 1024;
/* Bump up the resource limit for ourselves substantially */
nl.rlim_cur = nl.rlim_max = min_max;
r = setrlimit_closest(RLIMIT_NOFILE, &nl);
/* Bump up the resource limit for ourselves substantially, all the way to the maximum the kernel allows */
nr = read_nr_open();
r = setrlimit_closest(RLIMIT_NOFILE, &RLIMIT_MAKE_CONST(nr));
if (r < 0)
return log_warning_errno(r, "Setting RLIMIT_NOFILE failed, ignoring: %m");