From: Igor Tsiglyar Date: Mon, 3 Jul 2023 13:51:32 +0000 (+0300) Subject: journal-remote: upload journals from namespace X-Git-Tag: v254-rc1~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9f6e0bd417fa287dd1e7b541bfe0c60f04cc29e4;p=thirdparty%2Fsystemd.git journal-remote: upload journals from namespace --- diff --git a/man/systemd-journal-upload.service.xml b/man/systemd-journal-upload.service.xml index ce9bbdf1516..57d72af96bf 100644 --- a/man/systemd-journal-upload.service.xml +++ b/man/systemd-journal-upload.service.xml @@ -98,6 +98,17 @@ journalctl1. + + + + Takes a journal namespace identifier string as argument. Upload + entries from the specified journal namespace + NAMESPACE instead of the default namespace. This has the same meaning as + option for + journalctl1. + + + diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 32da75e598b..22f318f314b 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -50,7 +50,9 @@ static char **arg_file = NULL; static const char *arg_cursor = NULL; static bool arg_after_cursor = false; static int arg_journal_type = 0; +static int arg_namespace_flags = 0; static const char *arg_machine = NULL; +static const char *arg_namespace = NULL; static bool arg_merge = false; static int arg_follow = -1; static const char *arg_save_state = NULL; @@ -557,6 +559,7 @@ static int help(void) { " --user Use the user journal for the current user\n" " -m --merge Use all available journals\n" " -M --machine=CONTAINER Operate on local container\n" + " --namespace=NAMESPACE Use journal files from namespace\n" " -D --directory=PATH Use journal files from directory\n" " --file=PATH Use this journal file\n" " --cursor=CURSOR Start at the specified cursor\n" @@ -584,6 +587,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_AFTER_CURSOR, ARG_FOLLOW, ARG_SAVE_STATE, + ARG_NAMESPACE, }; static const struct option options[] = { @@ -597,6 +601,7 @@ static int parse_argv(int argc, char *argv[]) { { "user", no_argument, NULL, ARG_USER }, { "merge", no_argument, NULL, 'm' }, { "machine", required_argument, NULL, 'M' }, + { "namespace", required_argument, NULL, ARG_NAMESPACE }, { "directory", required_argument, NULL, 'D' }, { "file", required_argument, NULL, ARG_FILE }, { "cursor", required_argument, NULL, ARG_CURSOR }, @@ -673,6 +678,23 @@ static int parse_argv(int argc, char *argv[]) { arg_machine = optarg; break; + case ARG_NAMESPACE: + if (streq(optarg, "*")) { + arg_namespace_flags = SD_JOURNAL_ALL_NAMESPACES; + arg_namespace = NULL; + } else if (startswith(optarg, "+")) { + arg_namespace_flags = SD_JOURNAL_INCLUDE_DEFAULT_NAMESPACE; + arg_namespace = optarg + 1; + } else if (isempty(optarg)) { + arg_namespace_flags = 0; + arg_namespace = NULL; + } else { + arg_namespace_flags = 0; + arg_namespace = optarg; + } + + break; + case 'D': if (arg_directory) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), @@ -757,7 +779,10 @@ static int open_journal(sd_journal **j) { /* FIXME: replace with D-Bus call OpenMachineRootDirectory() so that things also work with raw disk images */ r = sd_journal_open_container(j, arg_machine, 0); #pragma GCC diagnostic pop - } else + } else if (arg_namespace) + r = sd_journal_open_namespace(j, arg_namespace, (arg_merge ? 0 : SD_JOURNAL_LOCAL_ONLY) | + arg_namespace_flags | arg_journal_type); + else 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",