1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-14 04:58:28 +03:00

dissect: add --quiet mode

This commit is contained in:
Lennart Poettering 2025-02-07 19:44:13 +01:00
parent 6b3fd03eac
commit 172fadda65
2 changed files with 27 additions and 5 deletions

View File

@ -206,9 +206,12 @@
<listitem><para>Attach the specified disk image to an automatically allocated loopback block device,
and print the path to the loopback block device to standard output. This is similar to an invocation
of <command>losetup --find --show</command>, but will validate the image as DDI before attaching, and
derive the correct sector size to use automatically. Moreover, it ensures the per-partition block
devices are created before returning. Takes a path to a disk image file.</para>
of <command>losetup --find --show --partscan</command>, but will validate the image as DDI before
attaching, and derive the correct sector size to use automatically. Moreover, it ensures the
per-partition block devices are created before returning and attempts to enable direct IO mode, if
possible. Takes a path to a disk image file.</para>
<para>If combined with <option>--quiet</option> output of the block device name is suppressed.</para>
<xi:include href="version-info.xml" xpointer="v254"/></listitem>
</varlistentry>
@ -556,6 +559,16 @@
<xi:include href="version-info.xml" xpointer="v258"/></listitem>
</varlistentry>
<varlistentry>
<term><option>--quiet</option></term>
<term><option>-q</option></term>
<listitem><para>If combined with <option>--attach</option>, suppresses output of the used loopback
block device path.</para>
<xi:include href="version-info.xml" xpointer="v258"/></listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="image-policy-open" />
<xi:include href="standard-options.xml" xpointer="no-pager" />
<xi:include href="standard-options.xml" xpointer="no-legend" />

View File

@ -101,6 +101,7 @@ static bool arg_via_service = false;
static RuntimeScope arg_runtime_scope = _RUNTIME_SCOPE_INVALID;
static bool arg_all = false;
static uid_t arg_uid_base = UID_INVALID;
static bool arg_quiet = false;
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
@ -181,6 +182,7 @@ static int help(void) {
" --discover Discover DDIs in well known directories\n"
" --validate Validate image and image policy\n"
" --shift Shift UID range to selected base\n"
" -q --quiet Suppress output of chosen loopback block device\n"
"\nSee the %2$s for details.\n",
program_invocation_short_name,
link,
@ -329,6 +331,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "system", no_argument, NULL, ARG_SYSTEM },
{ "user", no_argument, NULL, ARG_USER },
{ "all", no_argument, NULL, ARG_ALL },
{ "quiet", no_argument, NULL, 'q' },
{}
};
@ -343,7 +346,7 @@ static int parse_argv(int argc, char *argv[]) {
if (r < 0)
return r;
while ((c = getopt_long(argc, argv, "hmurMUlxa", options, NULL)) >= 0) {
while ((c = getopt_long(argc, argv, "hmurMUlxaq", options, NULL)) >= 0) {
switch (c) {
@ -585,6 +588,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_all = true;
break;
case 'q':
arg_quiet = true;
break;
case '?':
return -EINVAL;
@ -1991,7 +1998,9 @@ static int action_attach(DissectedImage *m, LoopDevice *d) {
if (r < 0)
return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
puts(d->node);
if (!arg_quiet)
puts(d->node);
return 0;
}