X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=c0f60669d287857e7c9520399756ad564f98fc44;hb=f7818748090c534b8d835b970373936463bff84a;hp=950e730b995b89af52073b0ba8eaf0906d4147a9;hpb=5be946cda7b8e2271ade6188ca3f5dc068826619;p=petitboot diff --git a/discover/device-handler.c b/discover/device-handler.c index 950e730..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 @@ -38,7 +72,7 @@ static void context_commit(struct device_handler *handler, { struct discover_device *dev = ctx->device; struct discover_boot_option *opt, *tmp; - unsigned int i, existing_device; + unsigned int i, existing_device = 0; /* do we already have this device? */ for (i = 0; i < handler->n_devices; i++) { @@ -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); }