From: Daan De Meyer Date: Thu, 17 Aug 2023 13:07:57 +0000 (+0200) Subject: dissect: Set SYSTEMD_DISSECT_DEVICE to path of loop device X-Git-Tag: v255-rc1~696 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47838b55c87328aa0c7e3af06b358ba242f506b3;p=thirdparty%2Fsystemd.git dissect: Set SYSTEMD_DISSECT_DEVICE to path of loop device For some use cases we want to operate on the loop device that systemd-dissect has attached the loop device to, so let's make that easily accessible. --- diff --git a/man/systemd-dissect.xml b/man/systemd-dissect.xml index 27c5d3c7a84..29f19af7cc4 100644 --- a/man/systemd-dissect.xml +++ b/man/systemd-dissect.xml @@ -235,7 +235,8 @@ use to switch to read-only operation. The invoked process will have the $SYSTEMD_DISSECT_ROOT environment variable set, containing the absolute path name of the temporary mount point, i.e. the same directory that is set as the current working - directory. + directory. It will also have the $SYSTEMD_DISSECT_DEVICE environment variable set, + containing the absolute path name of the loop device the image was attached to. diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index 103ee41fe7f..291cb66375d 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -1577,6 +1577,11 @@ static int action_with(DissectedImage *m, LoopDevice *d) { _exit(EXIT_FAILURE); } + if (setenv("SYSTEMD_DISSECT_DEVICE", d->node, /* overwrite= */ true) < 0) { + log_error_errno(errno, "Failed to set $SYSTEMD_DISSECT_DEVICE: %m"); + _exit(EXIT_FAILURE); + } + if (strv_isempty(arg_argv)) { const char *sh;