From: Mike Yuan Date: Sat, 17 Aug 2024 17:53:09 +0000 (+0200) Subject: shared/logs-show: introduce journal_browse_prepare() X-Git-Tag: v257-rc1~648^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F34097%2Fhead;p=thirdparty%2Fsystemd.git shared/logs-show: introduce journal_browse_prepare() which combines sigbus_install() and bumping fd limit. --- diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 8de86a78971..e7d0dd34c0d 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -29,6 +29,7 @@ #include "journal-util.h" #include "json-util.h" #include "log.h" +#include "logs-show.h" #include "macro.h" #include "main-func.h" #include "mount-util.h" @@ -39,7 +40,6 @@ #include "pretty-print.h" #include "process-util.h" #include "rlimit-util.h" -#include "sigbus.h" #include "signal-util.h" #include "string-util.h" #include "strv.h" @@ -1378,14 +1378,11 @@ static int run(int argc, char *argv[]) { setlocale(LC_ALL, ""); log_setup(); - /* 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) return r; - sigbus_install(); + journal_browse_prepare(); units_active = check_units_active(); /* error is treated the same as 0 */ diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index dd91f229230..73b22170e79 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -32,7 +32,6 @@ #include "os-util.h" #include "parse-util.h" #include "pretty-print.h" -#include "sigbus.h" #include "signal-util.h" #include "time-util.h" #include "tmpfile-util.h" @@ -1134,7 +1133,8 @@ static int run(int argc, char *argv[]) { if (r <= 0) return r; - sigbus_install(); + journal_browse_prepare(); + assert_se(sigaction(SIGTERM, &sigterm, NULL) >= 0); r = setup_gnutls_logger(NULL); diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c index 34d4062d4a2..1cc978d383e 100644 --- a/src/journal-remote/journal-remote-main.c +++ b/src/journal-remote/journal-remote-main.c @@ -13,6 +13,7 @@ #include "fileio.h" #include "journal-remote-write.h" #include "journal-remote.h" +#include "logs-show.h" #include "main-func.h" #include "memory-util.h" #include "parse-argument.h" @@ -20,7 +21,6 @@ #include "pretty-print.h" #include "process-util.h" #include "rlimit-util.h" -#include "sigbus.h" #include "signal-util.h" #include "socket-netlink.h" #include "socket-util.h" @@ -1072,11 +1072,6 @@ static int run(int argc, char **argv) { log_setup(); - /* The journal merging logic potentially needs a lot of fds. */ - (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); - - sigbus_install(); - r = parse_config(); if (r < 0) return r; @@ -1085,6 +1080,8 @@ static int run(int argc, char **argv) { if (r <= 0) return r; + journal_browse_prepare(); + if (arg_listen_http || arg_listen_https) { r = setup_gnutls_logger(arg_gnutls_log); if (r < 0) diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index f6b9351907e..eb36d03130c 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -23,6 +23,7 @@ #include "journal-upload.h" #include "journal-util.h" #include "log.h" +#include "logs-show.h" #include "main-func.h" #include "mkdir.h" #include "parse-argument.h" @@ -30,7 +31,6 @@ #include "pretty-print.h" #include "process-util.h" #include "rlimit-util.h" -#include "sigbus.h" #include "signal-util.h" #include "string-util.h" #include "strv.h" @@ -766,9 +766,6 @@ static int run(int argc, char **argv) { log_setup(); - /* The journal merging logic potentially needs a lot of fds. */ - (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); - r = parse_config(); if (r < 0) return r; @@ -777,7 +774,7 @@ static int run(int argc, char **argv) { if (r <= 0) return r; - sigbus_install(); + journal_browse_prepare(); r = setup_uploader(&u, arg_url, arg_save_state); if (r < 0) diff --git a/src/journal/bsod.c b/src/journal/bsod.c index 2116c498a4b..cdf9e4874c3 100644 --- a/src/journal/bsod.c +++ b/src/journal/bsod.c @@ -20,7 +20,6 @@ #include "parse-argument.h" #include "pretty-print.h" #include "qrcode-util.h" -#include "sigbus.h" #include "signal-util.h" #include "sysctl-util.h" #include "terminal-util.h" @@ -307,12 +306,12 @@ static int run(int argc, char *argv[]) { log_setup(); - sigbus_install(); - r = parse_argv(argc, argv); if (r <= 0) return r; + journal_browse_prepare(); + r = acquire_first_emergency_log_message(&message); if (r < 0) return r; diff --git a/src/journal/journalctl-util.c b/src/journal/journalctl-util.c index b554f4d78a5..1996bddf605 100644 --- a/src/journal/journalctl-util.c +++ b/src/journal/journalctl-util.c @@ -8,7 +8,6 @@ #include "journalctl-util.h" #include "logs-show.h" #include "rlimit-util.h" -#include "sigbus.h" #include "strv.h" #include "terminal-util.h" @@ -27,11 +26,7 @@ int acquire_journal(sd_journal **ret) { assert(ret); - /* 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); - - sigbus_install(); + journal_browse_prepare(); if (arg_directory) r = sd_journal_open_directory(&j, arg_directory, arg_journal_type | arg_journal_additional_open_flags); diff --git a/src/login/loginctl.c b/src/login/loginctl.c index bfe22cd4bb0..c538b61e0d8 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -29,7 +29,6 @@ #include "pretty-print.h" #include "process-util.h" #include "rlimit-util.h" -#include "sigbus.h" #include "signal-util.h" #include "string-table.h" #include "strv.h" @@ -1716,15 +1715,12 @@ static int run(int argc, char *argv[]) { setlocale(LC_ALL, ""); log_setup(); - /* The journal merging logic potentially needs a lot of fds. */ - (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); - - sigbus_install(); - r = parse_argv(argc, argv); if (r <= 0) return r; + journal_browse_prepare(); + r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &bus); if (r < 0) return bus_log_connect_error(r, arg_transport); diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 43b3964a472..80c2522f9a3 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -53,7 +53,6 @@ #include "process-util.h" #include "ptyfwd.h" #include "rlimit-util.h" -#include "sigbus.h" #include "signal-util.h" #include "sort-util.h" #include "stdio-util.h" @@ -2430,14 +2429,12 @@ static int run(int argc, char *argv[]) { setlocale(LC_ALL, ""); log_setup(); - /* The journal merging logic potentially needs a lot of fds. */ - (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); - sigbus_install(); - r = parse_argv(argc, argv); if (r <= 0) return r; + journal_browse_prepare(); + if (STRPTR_IN_SET(argv[optind], "import-tar", "import-raw", "import-fs", "export-tar", "export-raw", diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 058d801a6c8..5c85135c9bd 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -3,6 +3,7 @@ #include #include "build.h" +#include "logs-show.h" #include "main-func.h" #include "networkctl.h" #include "networkctl-address-label.h" @@ -16,7 +17,6 @@ #include "parse-util.h" #include "path-util.h" #include "pretty-print.h" -#include "sigbus.h" #include "verbs.h" PagerFlags arg_pager_flags = 0; @@ -246,12 +246,12 @@ static int run(int argc, char* argv[]) { log_setup(); - sigbus_install(); - r = parse_argv(argc, argv); if (r <= 0) return r; + journal_browse_prepare(); + return networkctl_main(argc, argv); } diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h index d000978c047..ca35aa93f5e 100644 --- a/src/shared/logs-show.h +++ b/src/shared/logs-show.h @@ -11,7 +11,9 @@ #include "macro.h" #include "output-mode.h" +#include "rlimit-util.h" #include "set.h" +#include "sigbus.h" #include "time-util.h" typedef struct LogId { @@ -124,3 +126,11 @@ static inline int journal_get_boots( advance_older, max_ids, ret_ids, ret_n_ids); } + +static inline void journal_browse_prepare(void) { + /* 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); + + sigbus_install(); +} diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 912c1d83017..176fb137ab8 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -11,6 +11,7 @@ #include "capsule-util.h" #include "dissect-image.h" #include "install.h" +#include "logs-show.h" #include "main-func.h" #include "mount-util.h" #include "output-mode.h" @@ -21,7 +22,6 @@ #include "process-util.h" #include "reboot-util.h" #include "rlimit-util.h" -#include "sigbus.h" #include "signal-util.h" #include "stat-util.h" #include "string-table.h" @@ -1263,15 +1263,12 @@ static int run(int argc, char *argv[]) { setlocale(LC_ALL, ""); log_setup(); - /* The journal merging logic potentially needs a lot of fds. */ - (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); - - sigbus_install(); - r = systemctl_dispatch_parse_argv(argc, argv); if (r <= 0) goto finish; + journal_browse_prepare(); + if (proc_mounted() == 0) log_full(arg_no_warn ? LOG_DEBUG : LOG_WARNING, "%s%s/proc/ is not mounted. This is not a supported mode of operation. Please fix\n"