mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
coredumpctl: Add support for the --image option
This commit is contained in:
parent
71bdc96ab7
commit
05d9465675
@ -255,6 +255,19 @@
|
||||
</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>
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user