]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredumpctl: Add support for the --image option 24595/head
authorRichard Phibel <rphibel@googlemail.com>
Thu, 22 Sep 2022 15:23:01 +0000 (17:23 +0200)
committerRichard Phibel <rphibel@googlemail.com>
Mon, 3 Oct 2022 10:19:34 +0000 (12:19 +0200)
man/coredumpctl.xml
src/coredump/coredumpctl.c

index 52270a3e0782b9f87ac308336e7dfb12f1aeb78b..8002549f7d82b4a17b8700fa9518d293ae6c8c27 100644 (file)
         </para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--image=<replaceable>image</replaceable></option></term>
+
+        <listitem><para>Takes a path to a disk image file or block device node. If specified, all operations
+        are applied to file system in the indicated disk image. This option is similar to
+        <option>--root=</option>, but operates on file systems stored in disk images or block devices. The
+        disk image should either contain just a file system or a set of file systems within a GPT partition
+        table, following the <ulink url="https://systemd.io/DISCOVERABLE_PARTITIONS">Discoverable Partitions
+        Specification</ulink>. For further information on supported disk images, see
+        <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
+        switch of the same name.</para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><option>-q</option></term>
         <term><option>--quiet</option></term>
index 1de9106c8b96a1fcc8fc902f703d1b4bd0457c70..383d5716c432e897e8f68e236e344812347130de 100644 (file)
@@ -17,6 +17,7 @@
 #include "chase-symlinks.h"
 #include "compress.h"
 #include "def.h"
+#include "dissect-image.h"
 #include "fd-util.h"
 #include "format-table.h"
 #include "fs-util.h"
@@ -26,6 +27,7 @@
 #include "log.h"
 #include "macro.h"
 #include "main-func.h"
+#include "mount-util.h"
 #include "pager.h"
 #include "parse-argument.h"
 #include "parse-util.h"
@@ -51,6 +53,7 @@ static const char *arg_debugger = NULL;
 static char **arg_debugger_args = NULL;
 static const char *arg_directory = NULL;
 static char *arg_root = NULL;
+static char *arg_image = NULL;
 static char **arg_file = NULL;
 static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
 static PagerFlags arg_pager_flags = 0;
@@ -212,6 +215,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_DEBUGGER,
                 ARG_FILE,
                 ARG_ROOT,
+                ARG_IMAGE,
                 ARG_ALL,
         };
 
@@ -234,6 +238,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "quiet",              no_argument,       NULL, 'q'           },
                 { "json",               required_argument, NULL, ARG_JSON      },
                 { "root",               required_argument, NULL, ARG_ROOT      },
+                { "image",              required_argument, NULL, ARG_IMAGE     },
                 { "all",                no_argument,       NULL, ARG_ALL       },
                 {}
         };
@@ -330,6 +335,12 @@ static int parse_argv(int argc, char *argv[]) {
                                 return r;
                         break;
 
+                case ARG_IMAGE:
+                        r = parse_path_argument(optarg, false, &arg_image);
+                        if (r < 0)
+                                return r;
+                        break;
+
                 case 'r':
                         arg_reverse = true;
                         break;
@@ -361,8 +372,8 @@ static int parse_argv(int argc, char *argv[]) {
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                        "--since= must be before --until=.");
 
-        if ((!!arg_directory + !!arg_root) > 1)
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Please specify either --root= or -D/--directory=, the combination of these options is not supported.");
+        if ((!!arg_directory + !!arg_image + !!arg_root) > 1)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Please specify either --root=, --image= or -D/--directory=, the combination of these options is not supported.");
 
         return 1;
 }
@@ -1324,6 +1335,8 @@ static int coredumpctl_main(int argc, char *argv[]) {
 }
 
 static int run(int argc, char *argv[]) {
+        _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
+        _cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
         int r, units_active;
 
         setlocale(LC_ALL, "");
@@ -1340,6 +1353,25 @@ static int run(int argc, char *argv[]) {
 
         units_active = check_units_active(); /* error is treated the same as 0 */
 
+        if (arg_image) {
+                assert(!arg_root);
+
+                r = mount_image_privately_interactively(
+                                arg_image,
+                                DISSECT_IMAGE_GENERIC_ROOT |
+                                DISSECT_IMAGE_REQUIRE_ROOT |
+                                DISSECT_IMAGE_RELAX_VAR_CHECK |
+                                DISSECT_IMAGE_VALIDATE_OS,
+                                &mounted_dir,
+                                &loop_device);
+                if (r < 0)
+                        return r;
+
+                arg_root = strdup(mounted_dir);
+                if (!arg_root)
+                        return log_oom();
+        }
+
         r = coredumpctl_main(argc, argv);
 
         if (units_active > 0)