diff options
author | Luca Boccassi <luca.boccassi@microsoft.com> | 2022-01-25 15:49:22 +0000 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2022-01-25 22:22:47 +0000 |
commit | e3f7ed944ae750a40685c52349f3cc850db0876e (patch) | |
tree | 7c28734e38f32c41e3210286099ecc6c94fcbdce /src/portable/portabled-image-bus.c | |
parent | 0017415cc5f2b97e0f9812cb10984c364d4e03bc (diff) | |
download | systemd-e3f7ed944ae750a40685c52349f3cc850db0876e.tar.gz |
portable: add flag to return extension-releases in GetImageMetadataWithExtensions
Return the name of each extension and the associated extension-release
file, and pretty-print them in 'portablectl inspect', if a new flag
is passed.
$ portablectl inspect --extension app2 --extension app0 minimal app0 app1
(Matching unit files with prefixes 'app0', 'app1'.)
Image:
/run/portables/minimal.raw
Portable Service:
n/a
Operating System:
Debian GNU/Linux 10 (buster)
Extension:
/run/portables/app2.raw
Extension Scope:
n/a
Extension Compatibility Level:
n/a
Portable Service:
n/a
Portable Prefixes:
n/a
Operating System:
n/a (debian 10)
Extension:
/run/portables/app0.raw
Extension Scope:
n/a
Extension Compatibility Level:
n/a
Portable Service:
n/a
Portable Prefixes:
n/a
Operating System:
n/a (debian 10)
Unit files:
app0.service
Diffstat (limited to 'src/portable/portabled-image-bus.c')
-rw-r--r-- | src/portable/portabled-image-bus.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/portable/portabled-image-bus.c b/src/portable/portabled-image-bus.c index 4a1798ac52..6660498e51 100644 --- a/src/portable/portabled-image-bus.c +++ b/src/portable/portabled-image-bus.c @@ -102,13 +102,13 @@ int bus_image_common_get_metadata( Image *image, sd_bus_error *error) { + _cleanup_ordered_hashmap_free_ OrderedHashmap *extension_releases = NULL; _cleanup_(portable_metadata_unrefp) PortableMetadata *os_release = NULL; _cleanup_strv_free_ char **matches = NULL, **extension_images = NULL; _cleanup_hashmap_free_ Hashmap *unit_files = NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; _cleanup_free_ PortableMetadata **sorted = NULL; - /* Unused for now, but added to the DBUS methods for future-proofing */ - uint64_t input_flags = 0; + PortableFlags flags = 0; size_t i; int r; @@ -133,14 +133,17 @@ int bus_image_common_get_metadata( if (sd_bus_message_is_method_call(message, NULL, "GetImageMetadataWithExtensions") || sd_bus_message_is_method_call(message, NULL, "GetMetadataWithExtensions")) { + uint64_t input_flags = 0; + r = sd_bus_message_read(message, "t", &input_flags); if (r < 0) return r; - /* Let clients know that this version doesn't support any flags */ - if (input_flags != 0) + + if ((input_flags & ~_PORTABLE_MASK_PUBLIC) != 0) return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid 'flags' parameter '%" PRIu64 "'", input_flags); + flags |= input_flags; } r = bus_image_acquire(m, @@ -161,6 +164,7 @@ int bus_image_common_get_metadata( matches, extension_images, &os_release, + &extension_releases, &unit_files, NULL, error); @@ -187,6 +191,32 @@ int bus_image_common_get_metadata( if (r < 0) return r; + /* If it was requested, also send back the extension path and the content + * of each extension-release file. Behind a flag, as it's an incompatible + * change. */ + if (FLAGS_SET(flags, PORTABLE_INSPECT_EXTENSION_RELEASES)) { + PortableMetadata *extension_release; + + ORDERED_HASHMAP_FOREACH(extension_release, extension_releases) { + + r = sd_bus_message_open_container(reply, 'e', "say"); + if (r < 0) + return r; + + r = sd_bus_message_append(reply, "s", extension_release->image_path); + if (r < 0) + return r; + + r = append_fd(reply, extension_release); + if (r < 0) + return r; + + r = sd_bus_message_close_container(reply); + if (r < 0) + return r; + } + } + for (i = 0; i < hashmap_size(unit_files); i++) { r = sd_bus_message_open_container(reply, 'e', "say"); |