From: Samuel BF <36460-samuelbf@users.noreply.framagit.org> Date: Thu, 29 Apr 2021 19:45:53 +0000 (+0200) Subject: Wider range of options for selecting entries for systemd-journal-gatewayd X-Git-Tag: v249-rc1~260 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c362a432af57d7fc6b58938afa82fabcb41c9e6c;p=thirdparty%2Fsystemd.git Wider range of options for selecting entries for systemd-journal-gatewayd Introducing --user, --system, --merge and --file flags, like for journalctl and systemd-journal-upload. --- diff --git a/man/systemd-journal-gatewayd.service.xml b/man/systemd-journal-gatewayd.service.xml index 43ceb97032c..5f4a0dbeff1 100644 --- a/man/systemd-journal-gatewayd.service.xml +++ b/man/systemd-journal-gatewayd.service.xml @@ -79,6 +79,30 @@ certificate from. The certificate must be in PEM format. + + + + + Limit served entries to entries from system + services and the kernel, or to entries from services of + current user. This has the same meaning as + and options + for + journalctl1. If + neither is specified, all accessible entries are served. + + + + + + + + Serve entries interleaved from all available + journals, including other machines. This has the same meaning + as option for + journalctl1. + + @@ -89,6 +113,19 @@ the default runtime and system journal paths. + + + + Takes a file glob as an argument. Serve + entries from the specified journal files matching + GLOB instead of the default runtime + and system journal paths. May be specified multiple times, in + which case files will be suitably interleaved. This has the same meaning as + option for + journalctl1. + + + diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index a2f166a881b..ab1cf7b1096 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -18,6 +18,7 @@ #include "errno-util.h" #include "fd-util.h" #include "fileio.h" +#include "glob-util.h" #include "hostname-util.h" #include "log.h" #include "logs-show.h" @@ -36,7 +37,10 @@ static char *arg_key_pem = NULL; static char *arg_cert_pem = NULL; static char *arg_trust_pem = NULL; +static bool arg_merge = false; +static int arg_journal_type = 0; static const char *arg_directory = NULL; +static char **arg_file = NULL; STATIC_DESTRUCTOR_REGISTER(arg_key_pem, erase_and_freep); STATIC_DESTRUCTOR_REGISTER(arg_cert_pem, freep); @@ -110,9 +114,11 @@ static int open_journal(RequestMeta *m) { return 0; if (arg_directory) - return sd_journal_open_directory(&m->journal, arg_directory, 0); + return sd_journal_open_directory(&m->journal, arg_directory, arg_journal_type); + else if (arg_file) + return sd_journal_open_files(&m->journal, (const char**) arg_file, 0); else - return sd_journal_open(&m->journal, SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_SYSTEM); + return sd_journal_open(&m->journal, (arg_merge ? 0 : SD_JOURNAL_LOCAL_ONLY) | arg_journal_type); } static int request_meta_ensure_tmp(RequestMeta *m) { @@ -860,7 +866,11 @@ static int help(void) { " --cert=CERT.PEM Server certificate in PEM format\n" " --key=KEY.PEM Server key in PEM format\n" " --trust=CERT.PEM Certificate authority certificate in PEM format\n" + " --system Serve system journal\n" + " --user Serve the user journal for the current user\n" + " -m --merge Serve all available journals\n" " -D --directory=PATH Serve journal files in directory\n" + " --file=PATH Serve this journal file\n" "\nSee the %s for details.\n", program_invocation_short_name, link); @@ -874,6 +884,10 @@ static int parse_argv(int argc, char *argv[]) { ARG_KEY, ARG_CERT, ARG_TRUST, + ARG_USER, + ARG_SYSTEM, + ARG_MERGE, + ARG_FILE, }; int r, c; @@ -884,7 +898,11 @@ static int parse_argv(int argc, char *argv[]) { { "key", required_argument, NULL, ARG_KEY }, { "cert", required_argument, NULL, ARG_CERT }, { "trust", required_argument, NULL, ARG_TRUST }, + { "user", no_argument, NULL, ARG_USER }, + { "system", no_argument, NULL, ARG_SYSTEM }, + { "merge", no_argument, NULL, 'm' }, { "directory", required_argument, NULL, 'D' }, + { "file", required_argument, NULL, ARG_FILE }, {} }; @@ -947,10 +965,29 @@ static int parse_argv(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --trust= is not available."); #endif + + case ARG_SYSTEM: + arg_journal_type |= SD_JOURNAL_SYSTEM; + break; + + case ARG_USER: + arg_journal_type |= SD_JOURNAL_CURRENT_USER; + break; + + case 'm': + arg_merge = true; + break; + case 'D': arg_directory = optarg; break; + case ARG_FILE: + r = glob_extend(&arg_file, optarg, GLOB_NOCHECK); + if (r < 0) + return log_error_errno(r, "Failed to add paths: %m"); + break; + case '?': return -EINVAL; diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index d7e45364a6e..c3d580e49e4 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -803,7 +803,7 @@ static int open_journal(sd_journal **j) { r = sd_journal_open_container(j, arg_machine, 0); #pragma GCC diagnostic pop } else - r = sd_journal_open(j, !arg_merge*SD_JOURNAL_LOCAL_ONLY + arg_journal_type); + r = sd_journal_open(j, (arg_merge ? 0 : SD_JOURNAL_LOCAL_ONLY) | arg_journal_type); if (r < 0) log_error_errno(r, "Failed to open %s: %m", arg_directory ? arg_directory : arg_file ? "files" : "journal");