]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: do not fail if ignorable img.v/ vpick dir is empty
authorLuca Boccassi <bluca@debian.org>
Thu, 12 Sep 2024 16:46:04 +0000 (18:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 13 Sep 2024 15:32:00 +0000 (17:32 +0200)
If the vpick directory is configured to be ignored if missing, do not
fail and just skip ahead.

Follow-up for 5e79dd96a88
Follow-up for 622efc544dc

src/core/namespace.c
test/units/TEST-50-DISSECT.dissect.sh

index bd4bd6205c10ebd59dbbba43b018427483c2d483..c04ddedf5d6b8875da428218f23a33851ee8cbdb 100644 (file)
@@ -528,11 +528,15 @@ static int append_extensions(
                               &result);
                 if (r < 0)
                         return r;
-                if (!result.path)
+                if (!result.path) {
+                        if (m->ignore_enoent)
+                                continue;
+
                         return log_debug_errno(
                                         SYNTHETIC_ERRNO(ENOENT),
                                         "No matching entry in .v/ directory %s found.",
                                         m->source);
+                }
 
                 r = verity_settings_load(&verity, result.path, /* root_hash_path= */ NULL, /* root_hash_sig_path= */ NULL);
                 if (r < 0)
@@ -575,10 +579,6 @@ static int append_extensions(
                 const char *e = *extension_directory;
                 bool ignore_enoent = false;
 
-                /* Pick up the counter where the ExtensionImages left it. */
-                if (asprintf(&mount_point, "%s/unit-extensions/%zu", private_namespace_dir, n_mount_images++) < 0)
-                        return -ENOMEM;
-
                 /* Look for any prefixes */
                 if (startswith(e, "-")) {
                         e++;
@@ -596,11 +596,19 @@ static int append_extensions(
                               &result);
                 if (r < 0)
                         return r;
-                if (!result.path)
+                if (!result.path) {
+                        if (ignore_enoent)
+                                continue;
+
                         return log_debug_errno(
                                         SYNTHETIC_ERRNO(ENOENT),
                                         "No matching entry in .v/ directory %s found.",
                                         e);
+                }
+
+                /* Pick up the counter where the ExtensionImages left it. */
+                if (asprintf(&mount_point, "%s/unit-extensions/%zu", private_namespace_dir, n_mount_images++) < 0)
+                        return -ENOMEM;
 
                 for (size_t j = 0; hierarchies && hierarchies[j]; ++j) {
                         char *prefixed_hierarchy = path_join(mount_point, hierarchies[j]);
index 15f663faf549ce9d2809d6d0a5d18fef600632fa..84b7c15bff6a1820127bc4807eb4920ea32de17f 100755 (executable)
@@ -427,14 +427,15 @@ systemctl is-active testservice-50e.service
 # Check vpick support in ExtensionImages=
 VBASE="vtest$RANDOM"
 VDIR="/tmp/$VBASE.v"
-mkdir "$VDIR"
+EMPTY_VDIR="/tmp/$VBASE-empty.v"
+mkdir "$VDIR" "$EMPTY_VDIR"
 
 ln -s /tmp/app0.raw "$VDIR/${VBASE}_0.raw"
 ln -s /tmp/app1.raw "$VDIR/${VBASE}_1.raw"
 
-systemd-run -P -p ExtensionImages="$VDIR" bash -c '/opt/script1.sh | grep ID'
+systemd-run -P -p ExtensionImages="$VDIR -$EMPTY_VDIR" bash -c '/opt/script1.sh | grep ID'
 
-rm -rf "$VDIR"
+rm -rf "$VDIR" "$EMPTY_VDIR"
 
 # ExtensionDirectories will set up an overlay
 mkdir -p "$IMAGE_DIR/app0" "$IMAGE_DIR/app1" "$IMAGE_DIR/app-nodistro" "$IMAGE_DIR/service-scoped-test"
@@ -502,14 +503,15 @@ systemctl is-active testservice-50f.service
 # Check vpick support in ExtensionDirectories=
 VBASE="vtest$RANDOM"
 VDIR="/tmp/$VBASE.v"
-mkdir "$VDIR"
+EMPTY_VDIR="/tmp/$VBASE-empty.v"
+mkdir "$VDIR" "$EMPTY_VDIR"
 
 ln -s "$IMAGE_DIR/app0" "$VDIR/${VBASE}_0"
 ln -s "$IMAGE_DIR/app1" "$VDIR/${VBASE}_1"
 
-systemd-run -P --property ExtensionDirectories="$VDIR" cat /opt/script1.sh | grep -q -F "extension-release.app2"
+systemd-run -P --property ExtensionDirectories="$VDIR -$EMPTY_VDIR" cat /opt/script1.sh | grep -q -F "extension-release.app2"
 
-rm -rf "$VDIR"
+rm -rf "$VDIR" "$EMPTY_VDIR"
 
 systemd-dissect --umount "$IMAGE_DIR/app0"
 systemd-dissect --umount "$IMAGE_DIR/app1"