]> git.ozlabs.org Git - petitboot/blobdiff - discover/device-handler.c
ui/common: Add discover_client_enumerate to re-add device data
[petitboot] / discover / device-handler.c
index 7f7081df5f6fc27abd033788d2202c5cca1988c2..22866e6600e29cb869c6196055447fa74b1619f8 100644 (file)
@@ -285,6 +285,9 @@ struct device_handler *device_handler_init(struct discover_server *server,
 
        parser_init();
 
+       if (config_get()->safe_mode)
+               return handler;
+
        rc = device_handler_init_sources(handler);
        if (rc) {
                talloc_free(handler);
@@ -441,6 +444,22 @@ static int default_option_priority(struct discover_boot_option *opt)
        return 0;
 }
 
+static bool device_allows_default(struct discover_device *dev)
+{
+       const char *dev_str;
+
+       dev_str = config_get()->boot_device;
+
+       if (!dev_str || !strlen(dev_str))
+               return true;
+
+       /* default devices are specified by UUIDs at present */
+       if (strcmp(dev->uuid, dev_str))
+               return false;
+
+       return true;
+}
+
 static void set_default(struct device_handler *handler,
                struct discover_boot_option *opt)
 {
@@ -449,6 +468,10 @@ static void set_default(struct device_handler *handler,
        if (!handler->autoboot_enabled)
                return;
 
+       /* do we allow default-booting from this device? */
+       if (!device_allows_default(opt->device))
+               return;
+
        new_prio = default_option_priority(opt);
 
        /* A negative priority indicates that we don't want to boot this device
@@ -794,7 +817,12 @@ void device_handler_cancel_default(struct device_handler *handler)
 void device_handler_update_config(struct device_handler *handler,
                struct config *config)
 {
-       config_set(config);
+       int rc;
+
+       rc = config_set(config);
+       if (rc)
+               return;
+
        discover_server_notify_config(handler->server, config);
        device_handler_reinit(handler);
 }
@@ -822,6 +850,13 @@ static int device_handler_init_sources(struct device_handler *handler)
 
 static void device_handler_reinit_sources(struct device_handler *handler)
 {
+       /* if we haven't initialised sources previously (becuase we started in
+        * safe mode), then init once here. */
+       if (!(handler->udev || handler->network || handler->user_event)) {
+               device_handler_init_sources(handler);
+               return;
+       }
+
        udev_reinit(handler->udev);
 
        network_shutdown(handler->network);