]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-config.c
Consolidate petitboot,tty and petitboot,console
[petitboot] / ui / ncurses / nc-config.c
index 24aac2b6e8d6f7fc61e2e271104e9802b9225e6d..1bc77e8ec44750b6385388fa902e3a83b552c5a6 100644 (file)
@@ -33,7 +33,7 @@
 #include "nc-config.h"
 #include "nc-widgets.h"
 
-#define N_FIELDS       42
+#define N_FIELDS       44
 
 extern struct help_text config_help_text;
 
@@ -67,6 +67,7 @@ struct config_screen {
 
        bool                    autoboot_enabled;
        bool                    ipmi_override;
+       bool                    net_override;
 
        struct {
                struct nc_widget_label          *autoboot_l;
@@ -108,10 +109,12 @@ struct config_screen {
 
                struct nc_widget_label          *allow_write_l;
                struct nc_widget_select         *allow_write_f;
-               struct nc_widget_label          *boot_tty_l;
-               struct nc_widget_select         *boot_tty_f;
-               struct nc_widget_label          *current_tty_l;
+               struct nc_widget_label          *boot_console_l;
+               struct nc_widget_select         *boot_console_f;
+               struct nc_widget_label          *manual_console_l;
+               struct nc_widget_label          *current_console_l;
 
+               struct nc_widget_label          *net_override_l;
                struct nc_widget_label          *safe_mode;
                struct nc_widget_button         *ok_b;
                struct nc_widget_button         *help_b;
@@ -199,8 +202,8 @@ static int screen_process_form(struct config_screen *screen)
        bool allow_write, autoboot;
        char *str, *end;
        struct config *config;
-       int i, n_boot_opts, rc, idx;
-       unsigned int *order, tty;
+       int i, n_boot_opts, rc;
+       unsigned int *order, idx;
        char mac[20];
 
        config = config_copy(screen, screen->cui->config);
@@ -336,16 +339,16 @@ static int screen_process_form(struct config_screen *screen)
        if (allow_write != config->allow_writes)
                config->allow_writes = allow_write;
 
-       if (config->n_tty) {
-               tty = widget_select_get_value(screen->widgets.boot_tty_f);
-               if (!config->boot_tty) {
-                       config->boot_tty = talloc_strdup(config,
-                                                       config->tty_list[tty]);
-               } else if (strncmp(config->boot_tty, config->tty_list[tty],
-                               strlen(config->boot_tty)) != 0) {
-                       talloc_free(config->boot_tty);
-                       config->boot_tty = talloc_strdup(config,
-                                                       config->tty_list[tty]);
+       if (config->n_consoles && !config->manual_console) {
+               idx = widget_select_get_value(screen->widgets.boot_console_f);
+               if (!config->boot_console) {
+                       config->boot_console = talloc_strdup(config,
+                                                       config->consoles[idx]);
+               } else if (strncmp(config->boot_console, config->consoles[idx],
+                               strlen(config->boot_console)) != 0) {
+                       talloc_free(config->boot_console);
+                       config->boot_console = talloc_strdup(config,
+                                                       config->consoles[idx]);
                }
        }
 
@@ -411,6 +414,7 @@ static void config_screen_layout_widgets(struct config_screen *screen)
        widget_move(wl, y, screen->label_x);
 
        wf = widget_select_base(screen->widgets.autoboot_f);
+       widget_set_visible(wf, true);
        widget_move(wf, y, screen->field_x);
        y += widget_height(wf);
 
@@ -472,7 +476,8 @@ static void config_screen_layout_widgets(struct config_screen *screen)
                widget_move(wf, y, screen->field_x);
                widget_move(wh, y, screen->field_x + widget_width(wf) + 1);
                y += 2;
-       }
+       } else
+               y += 1;
 
        if (screen->ipmi_override) {
                wl = widget_label_base(screen->widgets.ipmi_type_l);
@@ -582,33 +587,50 @@ static void config_screen_layout_widgets(struct config_screen *screen)
 
        y += 1;
 
-       show = screen->cui->config->safe_mode;
-       if (show) {
-               widget_move(widget_label_base(screen->widgets.safe_mode),
-                       y, screen->field_x);
-               y += 1;
-       }
-
        layout_pair(screen, y, screen->widgets.allow_write_l,
                    widget_select_base(screen->widgets.allow_write_f));
        y += widget_height(widget_select_base(screen->widgets.allow_write_f));
 
        y += 1;
 
-       if (widget_height(widget_select_base(screen->widgets.boot_tty_f))) {
-               layout_pair(screen, y, screen->widgets.boot_tty_l,
-                           widget_select_base(screen->widgets.boot_tty_f));
-               y += widget_height(widget_select_base(screen->widgets.boot_tty_f));
-               widget_move(widget_label_base(screen->widgets.current_tty_l),
+       if (screen->widgets.manual_console_l) {
+               layout_pair(screen, y++, screen->widgets.boot_console_l,
+                       widget_label_base(screen->widgets.manual_console_l));
+               widget_move(widget_label_base(screen->widgets.current_console_l),
+                       y, screen->field_x);
+               widget_set_visible(widget_select_base(
+                       screen->widgets.boot_console_f), false);
+               y += 2;
+       } else if (widget_height(widget_select_base(screen->widgets.boot_console_f))) {
+               layout_pair(screen, y, screen->widgets.boot_console_l,
+                           widget_select_base(screen->widgets.boot_console_f));
+               y += widget_height(widget_select_base(screen->widgets.boot_console_f));
+               widget_move(widget_label_base(screen->widgets.current_console_l),
                        y, screen->field_x);
                y += 2;
        } else {
                widget_set_visible(widget_label_base(
-                                       screen->widgets.boot_tty_l), false);
+                                       screen->widgets.boot_console_l), false);
                widget_set_visible(widget_select_base(
-                                       screen->widgets.boot_tty_f), false);
+                                       screen->widgets.boot_console_f), false);
                widget_set_visible(widget_label_base(
-                                       screen->widgets.current_tty_l), false);
+                                       screen->widgets.current_console_l), false);
+       }
+
+       if (screen->net_override) {
+               widget_move(widget_label_base(screen->widgets.net_override_l),
+                               y, screen->label_x);
+               widget_set_visible(widget_label_base(screen->widgets.net_override_l),
+                                       true);
+               y += 1;
+       }
+
+       if (screen->cui->config->safe_mode) {
+               widget_move(widget_label_base(screen->widgets.safe_mode),
+                       y, screen->label_x);
+               widget_set_visible(widget_label_base(screen->widgets.safe_mode),
+                                       true);
+               y += 1;
        }
 
        widget_move(widget_button_base(screen->widgets.ok_b),
@@ -772,7 +794,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 {
        struct nc_widgetset *set = screen->widgetset;
        struct interface_config *ifcfg;
-       char *str, *ip, *mask, *gw, *url, *tty;
+       char *str, *ip, *mask, *gw, *url, *tty, *label;
        enum net_conf_type type;
        unsigned int i;
        int add_len, clear_len, any_len, min_len = 20;
@@ -828,7 +850,6 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 
        for (i = 0; i < sysinfo->n_blockdevs; i++) {
                struct blockdev_info *bd = sysinfo->blockdevs[i];
-               char *label;
 
                label = talloc_asprintf(screen, _("disk: %s [uuid: %s]"),
                                bd->name, bd->uuid);
@@ -838,7 +859,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 
        for (i = 0; i < sysinfo->n_interfaces; i++) {
                struct interface_info *info = sysinfo->interfaces[i];
-               char *label, mac[20];
+               char mac[20];
 
                mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
 
@@ -849,7 +870,6 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        }
 
        for (i = DEVICE_TYPE_NETWORK; i < DEVICE_TYPE_UNKNOWN; i++) {
-               char *label;
 
                if (i == DEVICE_TYPE_ANY)
                        label = talloc_asprintf(screen, _("Any Device"));
@@ -890,7 +910,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        widget_textbox_set_validator_integer(screen->widgets.timeout_f, 0, 999);
 
        if (config->ipmi_bootdev) {
-               char *label = talloc_asprintf(screen,
+               label = talloc_asprintf(screen,
                                _("%s IPMI boot option: %s"),
                                config->ipmi_bootdev_persistent ?
                                "Persistent" : "Temporary",
@@ -959,6 +979,12 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                url = ifcfg->static_config.url;
        }
 
+       screen->net_override = ifcfg && ifcfg->override;
+       if (screen->net_override) {
+               screen->widgets.net_override_l = widget_new_label(set, 0, 0,
+                       _("Network Override Active! 'OK' will overwrite interface config"));
+       }
+
        screen->widgets.ip_addr_l = widget_new_label(set, 0, 0, _("IP/mask:"));
        screen->widgets.ip_addr_f = widget_new_textbox(set, 0, 0, 16, ip);
        screen->widgets.ip_mask_l = widget_new_label(set, 0, 0, "/");
@@ -1019,22 +1045,28 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                                _("Allow bootloader scripts to modify disks"),
                                config->allow_writes);
 
-       screen->widgets.boot_tty_l = widget_new_label(set, 0, 0,
-                       _("Default tty:"));
-       screen->widgets.boot_tty_f = widget_new_select(set, 0, 0,
+       screen->widgets.boot_console_l = widget_new_label(set, 0, 0,
+                       _("Boot console:"));
+       screen->widgets.boot_console_f = widget_new_select(set, 0, 0,
                                                COLS - screen->field_x - 1);
 
-       for (i = 0; i < config->n_tty; i++){
-               found = config->boot_tty &&
-                       strncmp(config->boot_tty, config->tty_list[i],
-                               strlen(config->boot_tty)) == 0;
-               widget_select_add_option(screen->widgets.boot_tty_f, i,
-                                       config->tty_list[i], found);
+       for (i = 0; i < config->n_consoles; i++){
+               found = config->boot_console &&
+                       strncmp(config->boot_console, config->consoles[i],
+                               strlen(config->boot_console)) == 0;
+               widget_select_add_option(screen->widgets.boot_console_f, i,
+                                       config->consoles[i], found);
+       }
+
+       if (config->manual_console) {
+               label = talloc_asprintf(screen, _("Manually set: '%s'"),
+                                       config->boot_console);
+               screen->widgets.manual_console_l = widget_new_label(set, 0, 0, label);
        }
 
        tty = talloc_asprintf(screen, _("Current interface: %s"),
                                ttyname(STDIN_FILENO));
-       screen->widgets.current_tty_l = widget_new_label(set, 0 , 0, tty);
+       screen->widgets.current_console_l = widget_new_label(set, 0 , 0, tty);
 
        screen->widgets.ok_b = widget_new_button(set, 0, 0, 10, _("OK"),
                        ok_click, screen);