#include <system/system.h>
#include <process/process.h>
#include <url/url.h>
+#include <i18n/i18n.h>
#include "device-handler.h"
#include "discover-server.h"
static int device_handler_init_sources(struct device_handler *handler);
static void device_handler_reinit_sources(struct device_handler *handler);
+static void device_handler_update_lang(const char *lang);
+
void discover_context_add_boot_option(struct discover_context *ctx,
struct discover_boot_option *boot_option)
{
parser_init();
+ if (config_get()->safe_mode)
+ return handler;
+
rc = device_handler_init_sources(handler);
if (rc) {
talloc_free(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]));
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)
{
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
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
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_update_lang(config->lang);
device_handler_reinit(handler);
}
#ifndef PETITBOOT_TEST
+static void device_handler_update_lang(const char *lang)
+{
+ const char *cur_lang;
+
+ if (!lang)
+ return;
+
+ cur_lang = setlocale(LC_ALL, NULL);
+ if (cur_lang && !strcmp(cur_lang, lang))
+ return;
+
+ setlocale(LC_ALL, lang);
+}
+
static int device_handler_init_sources(struct device_handler *handler)
{
/* init our device sources: udev, network and user events */
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);
#else
+static void device_handler_update_lang(const char *lang __attribute__((unused)))
+{
+}
+
static int device_handler_init_sources(
struct device_handler *handler __attribute__((unused)))
{