]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
portable: fix 'portablectl list' to show the actual state for extensions 31435/head
authorLuca Boccassi <bluca@debian.org>
Thu, 28 Mar 2024 14:16:39 +0000 (14:16 +0000)
committerLuca Boccassi <bluca@debian.org>
Thu, 28 Mar 2024 14:20:20 +0000 (14:20 +0000)
When listing images they are inspected one by one, so in case of a
portable with extensions they always resulted as not found.
Allow a partial match when listing, so that we can find the appropriate
unit that an image belongs to, and list the correct state as attached.

src/portable/portable.c
test/units/testsuite-29.sh

index a544a013421fce2d09eaaf0958325dab8dfda21e..60dc98c5baf313feca9252a499f37ac85ab5621c 100644 (file)
@@ -1664,7 +1664,7 @@ int portable_attach(
         return 0;
 }
 
-static bool marker_matches_images(const char *marker, const char *name_or_path, char **extension_image_paths) {
+static bool marker_matches_images(const char *marker, const char *name_or_path, char **extension_image_paths, bool match_all) {
         _cleanup_strv_free_ char **root_and_extensions = NULL;
         int r;
 
@@ -1675,7 +1675,9 @@ static bool marker_matches_images(const char *marker, const char *name_or_path,
          * list of images/paths. We enforce strict 1:1 matching, so that we are sure
          * we are detaching exactly what was attached.
          * For each image, starting with the root, we look for a token in the marker,
-         * and return a negative answer on any non-matching combination. */
+         * and return a negative answer on any non-matching combination.
+         * If a partial match is allowed, then return immediately once it is found, otherwise
+         * ensure that everything matches. */
 
         root_and_extensions = strv_new(name_or_path);
         if (!root_and_extensions)
@@ -1704,11 +1706,14 @@ static bool marker_matches_images(const char *marker, const char *name_or_path,
                         if (r < 0)
                                 return log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", *image_name_or_path);
 
-                        if (!streq(base_image, base_image_name_or_path))
-                                return false;
+                        if (!streq(base_image, base_image_name_or_path)) {
+                                if (match_all)
+                                        return false;
+                        } else if (!match_all)
+                                return true;
                 }
 
-        return true;
+        return match_all;
 }
 
 static int test_chroot_dropin(
@@ -1763,7 +1768,9 @@ static int test_chroot_dropin(
         if (!name_or_path)
                 r = true;
         else
-                r = marker_matches_images(marker, name_or_path, extension_image_paths);
+                /* When detaching we want to match exactly on all images, but when inspecting we only need
+                 * to get the state of one component */
+                r = marker_matches_images(marker, name_or_path, extension_image_paths, ret_marker != NULL);
 
         if (ret_marker)
                 *ret_marker = TAKE_PTR(marker);
index d529286c6ce01760bdcdcd93e5736b6b22cc1b51..7af0ed45786bbe4d6c7f4d0f06372ad9c8e9dc74 100755 (executable)
@@ -241,6 +241,12 @@ status="$(portablectl is-attached --extension app0 minimal_0)"
 status="$(portablectl is-attached --extension app1 minimal_0)"
 [[ "${status}" == "attached-runtime" ]]
 
+# Ensure 'portablectl list' shows the correct status for both images
+portablectl list
+portablectl list | grep -F "minimal_0" | grep -q -F "attached-runtime"
+portablectl list | grep -F "app0" | grep -q -F "attached-runtime"
+portablectl list | grep -F "app1" | grep -q -F "attached-runtime"
+
 portablectl detach --runtime --extension /usr/share/app0.raw /usr/share/minimal_0.raw app
 
 status="$(portablectl is-attached --extension app1 minimal_0)"