From f7818748090c534b8d835b970373936463bff84a Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Fri, 15 Mar 2013 15:33:39 +0800 Subject: discover: Finalise boot options during commit Once the discover context is committed, we need to turn the resources in struct discover_boot_option into strings in struct boot_option, so that the parser can display & edit the boot option. This may cause assertions if any of the boot options contain unresolved resources, we'll fix this in the next patch. Signed-off-by: Jeremy Kerr --- discover/device-handler.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'discover') diff --git a/discover/device-handler.c b/discover/device-handler.c index c661fbe..c0f6066 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -12,11 +12,13 @@ #include #include #include +#include #include "device-handler.h" #include "discover-server.h" #include "event.h" #include "parser.h" +#include "resource.h" #include "udev.h" #include "paths.h" #include "boot.h" @@ -29,6 +31,38 @@ struct device_handler { unsigned int n_devices; }; +static bool resource_is_resolved(struct resource *res) +{ + return !res || res->resolved; +} + +/* We only use this in an assert, which will disappear if we're compiling + * with NDEBUG, so we need the 'used' attribute for these builds */ +static bool __attribute__((used)) boot_option_is_resolved( + struct discover_boot_option *opt) +{ + return resource_is_resolved(opt->boot_image) && + resource_is_resolved(opt->initrd) && + resource_is_resolved(opt->icon); +} + +static void boot_option_finalise(struct discover_boot_option *opt) +{ + assert(boot_option_is_resolved(opt)); + + /* check that the parsers haven't set any of the final data */ + assert(!opt->option->boot_image_file); + assert(!opt->option->initrd_file); + assert(!opt->option->icon_file); + + if (opt->boot_image) + opt->option->boot_image_file = opt->boot_image->url->full; + if (opt->initrd) + opt->option->initrd_file = opt->initrd->url->full; + if (opt->icon) + opt->option->icon_file = opt->icon->url->full; +} + /** * context_commit - Commit a temporary discovery context to the handler, * and notify the clients about any new options / devices @@ -65,6 +99,7 @@ static void context_commit(struct device_handler *handler, list_remove(&opt->list); list_add(&dev->boot_options, &opt->list); talloc_steal(dev, opt); + boot_option_finalise(opt); discover_server_notify_boot_option_add(handler->server, opt->option); } -- cgit v1.2.1