]> git.ozlabs.org Git - petitboot/blobdiff - discover/device-handler.c
discover: check config.boot_device before setting a default
[petitboot] / discover / device-handler.c
index dd3aee92ca35d0385880b190f60a379494152ad8..b93cdfa1130cc5c956e6608a997c118a3786cd08 100644 (file)
@@ -344,6 +344,11 @@ void device_handler_remove(struct device_handler *handler,
                talloc_free(opt);
        }
 
+       /* if this is a network device, we have to unregister it from the
+        * network code */
+       if (device->device->type == DEVICE_TYPE_NETWORK)
+               network_unregister_device(handler->network, device);
+
        handler->n_devices--;
        memmove(&handler->devices[i], &handler->devices[i + 1],
                (handler->n_devices - i) * sizeof(handler->devices[0]));
@@ -373,7 +378,7 @@ static void countdown_status(struct device_handler *handler,
        status.progress = -1;
        status.detail = NULL;
        status.message = talloc_asprintf(handler,
-                       "Booting %s in %u sec", opt->option->name, sec);
+                       "Booting in %d sec: %s", sec, opt->option->name);
 
        discover_server_notify_boot_status(handler->server, &status);
 
@@ -436,6 +441,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)
 {
@@ -444,6 +465,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
@@ -646,6 +671,8 @@ void device_handler_add_device(struct device_handler *handler,
                                struct discover_device *, handler->n_devices);
        handler->devices[handler->n_devices - 1] = device;
 
+       if (device->device->type == DEVICE_TYPE_NETWORK)
+               network_register_device(handler->network, device);
 }
 
 /* Start discovery on a hotplugged device. The device will be in our devices