]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/logs-show: introduce journal_browse_prepare() 34097/head
authorMike Yuan <me@yhndnzj.com>
Sat, 17 Aug 2024 17:53:09 +0000 (19:53 +0200)
committerMike Yuan <me@yhndnzj.com>
Thu, 22 Aug 2024 18:33:22 +0000 (20:33 +0200)
which combines sigbus_install() and bumping fd limit.

src/coredump/coredumpctl.c
src/journal-remote/journal-gatewayd.c
src/journal-remote/journal-remote-main.c
src/journal-remote/journal-upload.c
src/journal/bsod.c
src/journal/journalctl-util.c
src/login/loginctl.c
src/machine/machinectl.c
src/network/networkctl.c
src/shared/logs-show.h
src/systemctl/systemctl.c

index 8de86a78971b9db2ad39f5102baed247d3817965..e7d0dd34c0d104d88f8db615c1ce41af41dd750a 100644 (file)
@@ -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 */
 
index dd91f229230167c745fe2d12623c9ab34315fdae..73b22170e7920d1357ac4327f80acdac44672538 100644 (file)
@@ -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);
index 34d4062d4a2b0df0c77a5c6ecda7b687fd9f7be2..1cc978d383eb1eaea919a4acd1404e4938303932 100644 (file)
@@ -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)
index f6b9351907e369ebaca3a6ae41b6bac6bcff8523..eb36d03130c3543dd6fc17508049d125a79894b6 100644 (file)
@@ -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)
index 2116c498a4b6f35a94126d37dc5e69a112e62659..cdf9e4874c3e9aca5bda94bf41afcc6414e53d2b 100644 (file)
@@ -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;
index b554f4d78a50dcebb560da364c89872d428e794d..1996bddf605856e67688168d169141969bddf15b 100644 (file)
@@ -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);
index bfe22cd4bb0ac760f68f2a9cc6f4abc13abc6d61..c538b61e0d82135f3809ad21358fa6d994de9836 100644 (file)
@@ -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);
index 43b3964a4724706cdc63fa153cc8aac557c47e91..80c2522f9a3cc1b9ea2a366618b8d41a3a372396 100644 (file)
@@ -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",
index 058d801a6c8c34b120c87f7c1b190994bd144945..5c85135c9bd55130257da40050000080f6e382d1 100644 (file)
@@ -3,6 +3,7 @@
 #include <getopt.h>
 
 #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);
 }
 
index d000978c04751b6bcc4c63223b21ae0f96a5731e..ca35aa93f5ef10b1393c8c7430264e653fe3d08a 100644 (file)
@@ -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();
+}
index 912c1d83017f4b64e7167a37ad20c1a10bf54f26..176fb137ab802f56679e0d96cb35a1930143439f 100644 (file)
@@ -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"