summaryrefslogtreecommitdiff
path: root/src/coredump
diff options
context:
space:
mode:
authorRichard Phibel <rphibel@googlemail.com>2022-09-22 17:23:01 +0200
committerRichard Phibel <rphibel@googlemail.com>2022-10-03 12:19:34 +0200
commit05d94656753fe2fb098b0237480ca7da80182d03 (patch)
tree585147e32fa190deedb63b0b33eb42c262ce181f /src/coredump
parent71bdc96ab7d851e64757c58e3675cb66a0f00754 (diff)
downloadsystemd-05d94656753fe2fb098b0237480ca7da80182d03.tar.gz
coredumpctl: Add support for the --image option
Diffstat (limited to 'src/coredump')
-rw-r--r--src/coredump/coredumpctl.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c
index 1de9106c8b..383d5716c4 100644
--- a/src/coredump/coredumpctl.c
+++ b/src/coredump/coredumpctl.c
@@ -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)