]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect: Set SYSTEMD_DISSECT_DEVICE to path of loop device
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 17 Aug 2023 13:07:57 +0000 (15:07 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 17 Aug 2023 18:36:51 +0000 (20:36 +0200)
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
src/dissect/dissect.c

index 27c5d3c7a84858764afd839eeb2e1b1ce44b4211..29f19af7cc421953f7cc29d39ec2a4cc87ff93e0 100644 (file)
         use <option>--read-only</option> to switch to read-only operation. The invoked process will have the
         <varname>$SYSTEMD_DISSECT_ROOT</varname> 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.</para></listitem>
+        directory. It will also have the <varname>$SYSTEMD_DISSECT_DEVICE</varname> environment variable set,
+        containing the absolute path name of the loop device the image was attached to.</para></listitem>
       </varlistentry>
 
       <varlistentry>
index 103ee41fe7fc7615e2b80fffde2004fffc949e70..291cb66375dd23bbed341ce62da37e5be2ec3774 100644 (file)
@@ -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;