]> git.ozlabs.org Git - petitboot/blobdiff - discover/device-handler.c
ui/ncurses: Handle arrow key variants
[petitboot] / discover / device-handler.c
index f1270c8ca660b7c771f0e08023e4559345f1e5bc..8ad885f68225c031efc6de9b0b9f570776a53662 100644 (file)
@@ -18,6 +18,7 @@
 #include <process/process.h>
 #include <url/url.h>
 #include <i18n/i18n.h>
+#include <pb-config/pb-config.h>
 
 #include <sys/sysmacros.h>
 #include <sys/types.h>
@@ -338,6 +339,22 @@ const char *discover_device_get_param(struct discover_device *device,
        return NULL;
 }
 
+static void set_env_variables(const struct config *config)
+{
+       if (config->http_proxy)
+               setenv("http_proxy", config->http_proxy, 1);
+       else
+               unsetenv("http_proxy");
+
+       if (config->https_proxy)
+               setenv("https_proxy", config->https_proxy, 1);
+       else
+               unsetenv("https_proxy");
+
+       /* Reduce noise in the log from LVM listing open file descriptors */
+       setenv("LVM_SUPPRESS_FD_WARNINGS", "1", 1);
+}
+
 struct device_handler *device_handler_init(struct discover_server *server,
                struct waitset *waitset, int dry_run)
 {
@@ -362,6 +379,8 @@ struct device_handler *device_handler_init(struct discover_server *server,
        if (config_get()->safe_mode)
                return handler;
 
+       set_env_variables(config_get());
+
        rc = device_handler_init_sources(handler);
        if (rc) {
                talloc_free(handler);
@@ -375,6 +394,7 @@ void device_handler_reinit(struct device_handler *handler)
 {
        struct discover_boot_option *opt, *tmp;
        struct ramdisk_device *ramdisk;
+       struct config *config;
        unsigned int i;
 
        device_handler_cancel_default(handler);
@@ -420,6 +440,16 @@ void device_handler_reinit(struct device_handler *handler)
 
        discover_server_notify_plugins_remove(handler->server);
 
+       set_env_variables(config_get());
+
+       /* If the safe mode warning was active disable it now */
+       if (config_get()->safe_mode) {
+               config = config_copy(handler, config_get());
+               config->safe_mode = false;
+               config_set(config);
+               discover_server_notify_config(handler->server, config);
+       }
+
        device_handler_reinit_sources(handler);
 }
 
@@ -1762,6 +1792,20 @@ static int mount_device(struct discover_device *dev)
        rc = try_mount(device_path, dev->mount_path, fstype,
                       MS_RDONLY | MS_SILENT, dev->ramdisk);
 
+       /* If mount fails clean up any snapshot and try again */
+       if (rc && dev->ramdisk) {
+               pb_log("couldn't mount snapshot for %s: mount failed: %s\n",
+                               device_path, strerror(errno));
+               pb_log("falling back to actual device\n");
+
+               devmapper_destroy_snapshot(dev);
+
+               device_path = get_device_path(dev);
+               pb_log("mounting device %s read-only\n", dev->device_path);
+               rc = try_mount(device_path, dev->mount_path, fstype,
+                              MS_RDONLY | MS_SILENT, dev->ramdisk);
+       }
+
        if (!rc) {
                dev->mounted = true;
                dev->mounted_rw = false;
@@ -1773,9 +1817,6 @@ static int mount_device(struct discover_device *dev)
        pb_log("couldn't mount device %s: mount failed: %s\n",
                        device_path, strerror(errno));
 
-       /* If mount fails clean up any snapshot */
-       devmapper_destroy_snapshot(dev);
-
        pb_rmdir_recursive(mount_base(), dev->mount_path);
 err_free:
        talloc_free(dev->mount_path);