From 47838b55c87328aa0c7e3af06b358ba242f506b3 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 17 Aug 2023 15:07:57 +0200 Subject: [PATCH] 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. --- man/systemd-dissect.xml | 3 ++- src/dissect/dissect.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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; -- 2.47.3