From 1abaf4887dde91bd19b36a80475a8eb03f363590 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 1 Oct 2018 17:44:46 +0200 Subject: [PATCH] tree-wide: uniformly bump RLIMIT_NOFILE in all our tools that access the journal This makes use of rlimit_nofile_bump() in all tools that access the journal. In some cases this replaces older code to achieve this, and others we add it in where it was missing. --- src/coredump/coredumpctl.c | 5 +++++ src/journal-remote/journal-remote-main.c | 4 ++++ src/journal-remote/journal-upload.c | 4 ++++ src/journal/journalctl.c | 10 +++++----- src/login/loginctl.c | 5 +++++ src/machine/machinectl.c | 6 ++++++ src/systemctl/systemctl.c | 10 ++++------ 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 78e279d..8c08c64 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -15,6 +15,7 @@ #include "bus-error.h" #include "bus-util.h" #include "compress.h" +#include "def.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -26,6 +27,7 @@ #include "parse-util.h" #include "path-util.h" #include "process-util.h" +#include "rlimit-util.h" #include "sigbus.h" #include "signal-util.h" #include "string-util.h" @@ -1067,6 +1069,9 @@ int main(int argc, char *argv[]) { log_parse_environment(); log_open(); + /* The journal merging logic potentially needs a lot of fds. */ + (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); + r = parse_argv(argc, argv); if (r <= 0) goto end; diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c index 6d9b44e..b52e932 100644 --- a/src/journal-remote/journal-remote-main.c +++ b/src/journal-remote/journal-remote-main.c @@ -12,6 +12,7 @@ #include "journal-remote-write.h" #include "journal-remote.h" #include "process-util.h" +#include "rlimit-util.h" #include "signal-util.h" #include "socket-util.h" #include "stat-util.h" @@ -1096,6 +1097,9 @@ int main(int argc, char **argv) { log_show_color(true); log_parse_environment(); + /* The journal merging logic potentially needs a lot of fds. */ + (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); + r = parse_config(); if (r < 0) return EXIT_FAILURE; diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 621fd62..88fc51e 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -20,6 +20,7 @@ #include "mkdir.h" #include "parse-util.h" #include "process-util.h" +#include "rlimit-util.h" #include "sigbus.h" #include "signal-util.h" #include "string-util.h" @@ -780,6 +781,9 @@ int main(int argc, char **argv) { log_show_color(true); log_parse_environment(); + /* The journal merging logic potentially needs a lot of fds. */ + (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); + r = parse_config(); if (r < 0) goto finish; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 4d18601..9bd2d9a 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -31,6 +31,7 @@ #include "bus-util.h" #include "catalog.h" #include "chattr-util.h" +#include "def.h" #include "device-private.h" #include "fd-util.h" #include "fileio.h" @@ -2049,6 +2050,10 @@ int main(int argc, char *argv[]) { log_parse_environment(); log_open(); + /* Increase max number of open files if we can, we might needs this when browsing journal files, which might be + * split up into many files. */ + (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); + r = parse_argv(argc, argv); if (r <= 0) goto finish; @@ -2056,11 +2061,6 @@ int main(int argc, char *argv[]) { signal(SIGWINCH, columns_lines_cache_reset); sigbus_install(); - /* Increase max number of open files to 16K if we can, we - * might needs this when browsing journal files, which might - * be split up into many files. */ - setrlimit_closest(RLIMIT_NOFILE, &RLIMIT_MAKE_CONST(16384)); - switch (arg_action) { case ACTION_NEW_ID128: diff --git a/src/login/loginctl.c b/src/login/loginctl.c index c9c3166..39c24f8 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -21,6 +21,7 @@ #include "pager.h" #include "parse-util.h" #include "process-util.h" +#include "rlimit-util.h" #include "sigbus.h" #include "signal-util.h" #include "spawn-polkit-agent.h" @@ -1522,6 +1523,10 @@ int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); log_parse_environment(); log_open(); + + /* The journal merging logic potentially needs a lot of fds. */ + (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); + sigbus_install(); r = parse_argv(argc, argv); diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 2f21f99..d408d80 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -22,6 +22,7 @@ #include "cgroup-show.h" #include "cgroup-util.h" #include "copy.h" +#include "def.h" #include "env-util.h" #include "fd-util.h" #include "format-table.h" @@ -37,6 +38,7 @@ #include "path-util.h" #include "process-util.h" #include "ptyfwd.h" +#include "rlimit-util.h" #include "sigbus.h" #include "signal-util.h" #include "spawn-polkit-agent.h" @@ -3030,6 +3032,10 @@ int main(int argc, char*argv[]) { setlocale(LC_ALL, ""); log_parse_environment(); log_open(); + + /* The journal merging logic potentially needs a lot of fds. */ + (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); + sigbus_install(); r = parse_argv(argc, argv); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 90adeb9..5e3040f 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -5264,12 +5264,6 @@ static int show(int argc, char *argv[], void *userdata) { (void) pager_open(arg_no_pager, false); - if (show_mode == SYSTEMCTL_SHOW_STATUS) - /* Increase max number of open files to 16K if we can, we - * might needs this when browsing journal files, which might - * be split up into many files. */ - setrlimit_closest(RLIMIT_NOFILE, &RLIMIT_MAKE_CONST(16384)); - /* If no argument is specified inspect the manager itself */ if (show_mode == SYSTEMCTL_SHOW_PROPERTIES && argc <= 1) return show_one(bus, "/org/freedesktop/systemd1", NULL, show_mode, &new_line, &ellipsized); @@ -8661,6 +8655,10 @@ int main(int argc, char*argv[]) { setlocale(LC_ALL, ""); log_parse_environment(); log_open(); + + /* The journal merging logic potentially needs a lot of fds. */ + (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); + sigbus_install(); /* Explicitly not on_tty() to avoid setting cached value. -- 2.7.4