]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
portabled: error out if there are no units only after parsing all images
authorLuca Boccassi <luca.boccassi@microsoft.com>
Wed, 18 Aug 2021 15:37:13 +0000 (16:37 +0100)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Mon, 6 Sep 2021 11:13:53 +0000 (12:13 +0100)
It's ok if the OS image doesn't have matching units, if we find them
in the extensions. Tidies up the parsing logic a bit.

src/portable/portable.c

index b3fcf2719a77743517a617e30d28ef719c27acec..aa072f9489e0c34450c87e7f689d6a9caa42b1ba 100644 (file)
@@ -503,9 +503,6 @@ static int portable_extract_by_path(
         if (extract_os_release && !os_release)
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image '%s' lacks os-release data, refusing.", path);
 
-        if (!extract_os_release && hashmap_isempty(unit_files))
-                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Couldn't find any matching unit files in image '%s', refusing.", path);
-
         if (ret_unit_files)
                 *ret_unit_files = TAKE_PTR(unit_files);
 
@@ -572,6 +569,19 @@ int portable_extract(
                         return r;
         }
 
+        if (hashmap_isempty(unit_files)) {
+                _cleanup_free_ char *extensions = strv_join(extension_image_paths, ", ");
+                if (!extensions)
+                        return -ENOMEM;
+
+                return sd_bus_error_setf(error,
+                                         SD_BUS_ERROR_INVALID_ARGS,
+                                         "Couldn't find any matching unit files in image '%s%s%s', refusing.",
+                                         image->path,
+                                         isempty(extensions) ? "" : "' or any of its extensions '",
+                                         isempty(extensions) ? "" : extensions);
+        }
+
         *ret_os_release = TAKE_PTR(os_release);
         *ret_unit_files = TAKE_PTR(unit_files);
 
@@ -1188,6 +1198,19 @@ int portable_attach(
                         return r;
         }
 
+        if (hashmap_isempty(unit_files)) {
+                _cleanup_free_ char *extensions = strv_join(extension_image_paths, ", ");
+                if (!extensions)
+                        return -ENOMEM;
+
+                return sd_bus_error_setf(error,
+                                         SD_BUS_ERROR_INVALID_ARGS,
+                                         "Couldn't find any matching unit files in image '%s%s%s', refusing.",
+                                         image->path,
+                                         isempty(extensions) ? "" : "' or any of its extensions '",
+                                         isempty(extensions) ? "" : extensions);
+        }
+
         r = lookup_paths_init(&paths, UNIT_FILE_SYSTEM, LOOKUP_PATHS_SPLIT_USR, NULL);
         if (r < 0)
                 return r;