]> git.ozlabs.org Git - petitboot/blobdiff - discover/device-handler.c
Move --dry-run option to discover server
[petitboot] / discover / device-handler.c
index 0d4349671dfa6c375f223cde0f43877c41ddad71..12bd5aed63a20ee56b45cd12e19f7d98a12c1901 100644 (file)
 #include "parser.h"
 #include "udev.h"
 #include "paths.h"
+#include "boot.h"
 
 struct device_handler {
        struct discover_server *server;
+       int dry_run;
 
        struct device **devices;
        unsigned int n_devices;
@@ -406,7 +408,8 @@ int device_handler_event(struct device_handler *handler,
        return handlers[event->type][event->action](handler, event);
 }
 
-struct device_handler *device_handler_init(struct discover_server *server)
+struct device_handler *device_handler_init(struct discover_server *server,
+               int dry_run)
 {
        struct device_handler *handler;
 
@@ -414,6 +417,7 @@ struct device_handler *device_handler_init(struct discover_server *server)
        handler->devices = NULL;
        handler->n_devices = 0;
        handler->server = server;
+       handler->dry_run = dry_run;
 
        list_init(&handler->contexts);
 
@@ -429,3 +433,30 @@ void device_handler_destroy(struct device_handler *handler)
 {
        talloc_free(handler);
 }
+
+static struct boot_option *find_boot_option_by_id(
+               struct device_handler *handler, const char *id)
+{
+       unsigned int i;
+
+       for (i = 0; i < handler->n_devices; i++) {
+               struct device *dev = handler->devices[i];
+               struct boot_option *opt;
+
+               list_for_each_entry(&dev->boot_options, opt, list)
+                       if (!strcmp(opt->id, id))
+                               return opt;
+       }
+
+       return NULL;
+}
+
+void device_handler_boot(struct device_handler *handler,
+               struct boot_command *cmd)
+{
+       struct boot_option *opt;
+
+       opt = find_boot_option_by_id(handler, cmd->option_id);
+
+       boot(handler, opt, cmd, handler->dry_run);
+}