]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-remote: upload journals from namespace
authorIgor Tsiglyar <i.tsiglyar@yadro.com>
Mon, 3 Jul 2023 13:51:32 +0000 (16:51 +0300)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 4 Jul 2023 17:47:54 +0000 (18:47 +0100)
man/systemd-journal-upload.service.xml
src/journal-remote/journal-upload.c

index ce9bbdf1516c8d1dbd9508b6501f89a65e3bbe4c..57d72af96bf143a36e2a63877b959294181581df 100644 (file)
         <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--namespace=<replaceable>NAMESPACE</replaceable></option></term>
+
+        <listitem><para>Takes a journal namespace identifier string as argument. Upload
+        entries from the specified journal namespace
+        <replaceable>NAMESPACE</replaceable> instead of the default namespace. This has the same meaning as
+        <option>--namespace=</option> option for
+        <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
+        </para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><option>-D</option></term>
         <term><option>--directory=<replaceable>DIR</replaceable></option></term>
index 32da75e598b8a0071a2ac5d15f6d2d192066a87e..22f318f314bb5573f7e618a116d3f9b8a7a74e8a 100644 (file)
@@ -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",