1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 01:55:22 +03:00

shared/logs-show: introduce journal_browse_prepare()

which combines sigbus_install() and bumping fd limit.
This commit is contained in:
Mike Yuan 2024-08-17 19:53:09 +02:00
parent d71f138156
commit fad3feec12
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3
11 changed files with 32 additions and 47 deletions

View 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 */

View 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);

View 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)

View 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)

View 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;

View 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);

View 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);

View 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",

View 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);
}

View 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();
}

View 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"