[1/2] Use 'consoles' instead of 'tty' to refer to interfaces
diff mbox

Message ID 20160815053515.17877-1-sam@mendozajonas.com
State Accepted
Headers show

Commit Message

Samuel Mendoza-Jonas Aug. 15, 2016, 5:35 a.m. UTC
'Console' is more readily understandable and technically more correct
than 'tty' for referring to the interfaces that Petitboot starts a UI on.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 discover/boot.c               | 14 ++++-----
 discover/platform-powerpc.c   | 28 +++++++++---------
 discover/platform.c           |  8 +++---
 lib/pb-config/pb-config.c     | 18 ++++++------
 lib/pb-protocol/pb-protocol.c | 34 +++++++++++-----------
 lib/types/types.h             |  8 +++---
 ui/common/discover-client.c   |  2 +-
 ui/ncurses/nc-config.c        | 66 +++++++++++++++++++++----------------------
 utils/hooks/30-add-offb.c     | 25 ++++++++--------
 9 files changed, 103 insertions(+), 100 deletions(-)

Patch
diff mbox

diff --git a/discover/boot.c b/discover/boot.c
index ba6ce25..c301e8a 100644
--- a/discover/boot.c
+++ b/discover/boot.c
@@ -40,7 +40,7 @@  struct boot_task {
 	const char *local_initrd;
 	const char *local_dtb;
 	const char *args;
-	const char *boot_tty;
+	const char *boot_console;
 	boot_status_fn status_fn;
 	void *status_arg;
 	bool dry_run;
@@ -208,7 +208,7 @@  static void boot_hook_setenv(struct boot_task *task)
 	unsetenv("boot_initrd");
 	unsetenv("boot_dtb");
 	unsetenv("boot_args");
-	unsetenv("boot_tty");
+	unsetenv("boot_console");
 
 	setenv("boot_image", task->local_image, 1);
 	if (task->local_initrd)
@@ -217,8 +217,8 @@  static void boot_hook_setenv(struct boot_task *task)
 		setenv("boot_dtb", task->local_dtb, 1);
 	if (task->args)
 		setenv("boot_args", task->args, 1);
-	if (task->boot_tty)
-		setenv("boot_tty", task->boot_tty, 1);
+	if (task->boot_console)
+		setenv("boot_console", task->boot_console, 1);
 }
 
 static int hook_filter(const struct dirent *dirent)
@@ -487,11 +487,11 @@  struct boot_task *boot(void *ctx, struct discover_boot_option *opt,
 		boot_task->args = NULL;
 	}
 
-	if (cmd && cmd->tty)
-		boot_task->boot_tty = talloc_strdup(boot_task, cmd->tty);
+	if (cmd && cmd->console)
+		boot_task->boot_console = talloc_strdup(boot_task, cmd->console);
 	else {
 		config = config_get();
-		boot_task->boot_tty = config ? config->boot_tty : NULL;
+		boot_task->boot_console = config ? config->boot_console : NULL;
 	}
 
 	/* start async loads for boot resources */
diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index 8fca5bd..1636955 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -569,7 +569,7 @@  static void populate_config(struct platform_powerpc *platform,
 
 	val = get_param(platform, "petitboot,tty");
 	if (val)
-		config->boot_tty = talloc_strdup(config, val);
+		config->boot_console = talloc_strdup(config, val);
 }
 
 static char *iface_config_str(void *ctx, struct interface_config *config)
@@ -737,7 +737,7 @@  static int update_config(struct platform_powerpc *platform,
 		val = config->allow_writes ? "true" : "false";
 	update_string_config(platform, "petitboot,write?", val);
 
-	val = config->boot_tty ?: "";
+	val = config->boot_console ?: "";
 	update_string_config(platform, "petitboot,tty", val);
 
 	update_network_config(platform, config);
@@ -1230,32 +1230,32 @@  static void get_active_consoles(struct config *config)
 	struct stat sbuf;
 	char *fsp_prop = NULL;
 
-	config->n_tty = 2;
-	config->tty_list = talloc_array(config, char *, config->n_tty);
-	if (!config->tty_list)
+	config->n_consoles = 2;
+	config->consoles = talloc_array(config, char *, config->n_consoles);
+	if (!config->consoles)
 		goto err;
 
-	config->tty_list[0] = talloc_asprintf(config->tty_list,
+	config->consoles[0] = talloc_asprintf(config->consoles,
 					"/dev/hvc0 [IPMI / Serial]");
-	config->tty_list[1] = talloc_asprintf(config->tty_list,
+	config->consoles[1] = talloc_asprintf(config->consoles,
 					"/dev/tty1 [VGA]");
 
 	fsp_prop = talloc_asprintf(config, "%sfsps", devtree_dir);
 	if (stat(fsp_prop, &sbuf) == 0) {
 		/* FSP based machines also have a separate serial console */
-		config->tty_list = talloc_realloc(config, config->tty_list,
-						char *,	config->n_tty + 1);
-		if (!config->tty_list)
+		config->consoles = talloc_realloc(config, config->consoles,
+						char *,	config->n_consoles + 1);
+		if (!config->consoles)
 			goto err;
-		config->tty_list[config->n_tty++] = talloc_asprintf(
-						config->tty_list,
+		config->consoles[config->n_consoles++] = talloc_asprintf(
+						config->consoles,
 						"/dev/hvc1 [Serial]");
 	}
 
 	return;
 err:
-	config->n_tty = 0;
-	pb_log("Failed to allocate memory for tty_list\n");
+	config->n_consoles = 0;
+	pb_log("Failed to allocate memory for consoles\n");
 }
 
 static int load_config(struct platform *p, struct config *config)
diff --git a/discover/platform.c b/discover/platform.c
index 254da97..95a905d 100644
--- a/discover/platform.c
+++ b/discover/platform.c
@@ -83,7 +83,7 @@  static void dump_config(struct config *config)
 			config->allow_writes ? "yes" : "no");
 
 	pb_log("  Default UI to boot on: %s\n",
-		config->boot_tty ?: "none set");
+		config->boot_console ?: "none set");
 
 
 	pb_log(" language: %s\n", config->lang ?: "");
@@ -123,9 +123,9 @@  void config_set_defaults(struct config *config)
 	config->allow_writes = true;
 	config->disable_snapshots = false;
 
-	config->n_tty = 0;
-	config->tty_list = NULL;
-	config->boot_tty = NULL;
+	config->n_consoles = 0;
+	config->consoles = NULL;
+	config->boot_console = NULL;
 
 	config->n_autoboot_opts = 2;
 	config->autoboot_opts = talloc_array(config, struct autoboot_option,
diff --git a/lib/pb-config/pb-config.c b/lib/pb-config/pb-config.c
index 52a43b1..97115bc 100644
--- a/lib/pb-config/pb-config.c
+++ b/lib/pb-config/pb-config.c
@@ -82,15 +82,15 @@  struct config *config_copy(void *ctx, const struct config *src)
 
 	dest->allow_writes = src->allow_writes;
 
-	dest->n_tty = src->n_tty;
-	if (src->tty_list)
-		dest->tty_list = talloc_array(dest, char *, src->n_tty);
-	for (i = 0; i < src->n_tty && src->n_tty; i++)
-		dest->tty_list[i] = talloc_strdup(dest->tty_list,
-						src->tty_list[i]);
-
-	if (src->boot_tty)
-		dest->boot_tty = talloc_strdup(dest, src->boot_tty);
+	dest->n_consoles = src->n_consoles;
+	if (src->consoles)
+		dest->consoles = talloc_array(dest, char *, src->n_consoles);
+	for (i = 0; i < src->n_consoles && src->n_consoles; i++)
+		dest->consoles[i] = talloc_strdup(dest->consoles,
+						src->consoles[i]);
+
+	if (src->boot_console)
+		dest->boot_console = talloc_strdup(dest, src->boot_console);
 
 	if (src->lang && strlen(src->lang))
 		dest->lang = talloc_strdup(dest, src->lang);
diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c
index 7887fb0..adf2208 100644
--- a/lib/pb-protocol/pb-protocol.c
+++ b/lib/pb-protocol/pb-protocol.c
@@ -207,7 +207,7 @@  int pb_protocol_boot_len(const struct boot_command *boot)
 		4 + optional_strlen(boot->initrd_file) +
 		4 + optional_strlen(boot->dtb_file) +
 		4 + optional_strlen(boot->boot_args) +
-		4 + optional_strlen(boot->tty);
+		4 + optional_strlen(boot->console);
 }
 
 int pb_protocol_boot_status_len(const struct boot_status *status)
@@ -311,11 +311,11 @@  int pb_protocol_config_len(const struct config *config)
 
 	len += 4; /* allow_writes */
 
-	len += 4; /* n_tty */
-	for (i = 0; i < config->n_tty; i++)
-		len += 4 + optional_strlen(config->tty_list[i]);
+	len += 4; /* n_consoles */
+	for (i = 0; i < config->n_consoles; i++)
+		len += 4 + optional_strlen(config->consoles[i]);
 
-	len += 4 + optional_strlen(config->boot_tty);
+	len += 4 + optional_strlen(config->boot_console);
 
 	len += 4 + optional_strlen(config->lang);
 
@@ -380,7 +380,7 @@  int pb_protocol_serialise_boot_command(const struct boot_command *boot,
 	pos += pb_protocol_serialise_string(pos, boot->initrd_file);
 	pos += pb_protocol_serialise_string(pos, boot->dtb_file);
 	pos += pb_protocol_serialise_string(pos, boot->boot_args);
-	pos += pb_protocol_serialise_string(pos, boot->tty);
+	pos += pb_protocol_serialise_string(pos, boot->console);
 
 	assert(pos <= buf + buf_len);
 	(void)buf_len;
@@ -561,12 +561,12 @@  int pb_protocol_serialise_config(const struct config *config,
 	*(uint32_t *)pos = config->allow_writes;
 	pos += 4;
 
-	*(uint32_t *)pos = __cpu_to_be32(config->n_tty);
+	*(uint32_t *)pos = __cpu_to_be32(config->n_consoles);
 	pos += 4;
-	for (i = 0; i < config->n_tty; i++)
-		pos += pb_protocol_serialise_string(pos, config->tty_list[i]);
+	for (i = 0; i < config->n_consoles; i++)
+		pos += pb_protocol_serialise_string(pos, config->consoles[i]);
 
-	pos += pb_protocol_serialise_string(pos, config->boot_tty);
+	pos += pb_protocol_serialise_string(pos, config->boot_console);
 
 	pos += pb_protocol_serialise_string(pos, config->lang);
 
@@ -785,7 +785,7 @@  int pb_protocol_deserialise_boot_command(struct boot_command *cmd,
 	if (read_string(cmd, &pos, &len, &cmd->boot_args))
 		goto out;
 
-	if (read_string(cmd, &pos, &len, &cmd->tty))
+	if (read_string(cmd, &pos, &len, &cmd->console))
 		goto out;
 
 	rc = 0;
@@ -1087,20 +1087,20 @@  int pb_protocol_deserialise_config(struct config *config,
 		goto out;
 	config->allow_writes = !!tmp;
 
-	if (read_u32(&pos, &len, &config->n_tty))
+	if (read_u32(&pos, &len, &config->n_consoles))
 		goto out;
 
-	config->tty_list = talloc_array(config, char *, config->n_tty);
-	for (i = 0; i < config->n_tty; i++) {
-		if (read_string(config->tty_list, &pos, &len, &str))
+	config->consoles = talloc_array(config, char *, config->n_consoles);
+	for (i = 0; i < config->n_consoles; i++) {
+		if (read_string(config->consoles, &pos, &len, &str))
 			goto out;
-		config->tty_list[i] = str;
+		config->consoles[i] = str;
 	}
 
 	if (read_string(config, &pos, &len, &str))
 		goto out;
 
-	config->boot_tty = str;
+	config->boot_console = str;
 
 	if (read_string(config, &pos, &len, &str))
 		goto out;
diff --git a/lib/types/types.h b/lib/types/types.h
index 5c5f6ed..9154b35 100644
--- a/lib/types/types.h
+++ b/lib/types/types.h
@@ -65,7 +65,7 @@  struct boot_command {
 	char *initrd_file;
 	char *dtb_file;
 	char *boot_args;
-	char *tty;
+	char *console;
 };
 
 struct boot_status {
@@ -160,12 +160,12 @@  struct config {
 
 	bool			allow_writes;
 
-	char			*boot_tty;
+	char			*boot_console;
 	char			*lang;
 
 	/* not user-settable */
-	unsigned int		n_tty;
-	char			**tty_list;
+	unsigned int		n_consoles;
+	char			**consoles;
 	bool			disable_snapshots;
 	bool			safe_mode;
 	bool			debug;
diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c
index 6247dd0..a5baaac 100644
--- a/ui/common/discover-client.c
+++ b/ui/common/discover-client.c
@@ -312,7 +312,7 @@  static void create_boot_command(struct boot_command *command,
 	command->initrd_file = data->initrd;
 	command->dtb_file = data->dtb;
 	command->boot_args = data->args;
-	command->tty = ttyname(STDIN_FILENO);
+	command->console = ttyname(STDIN_FILENO);
 }
 
 int discover_client_boot(struct discover_client *client,
diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c
index 10d7eb6..7da2f06 100644
--- a/ui/ncurses/nc-config.c
+++ b/ui/ncurses/nc-config.c
@@ -108,9 +108,9 @@  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		*current_console_l;
 
 		struct nc_widget_label		*safe_mode;
 		struct nc_widget_button		*ok_b;
@@ -199,8 +199,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 +336,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) {
+		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]);
 		}
 	}
 
@@ -596,20 +596,20 @@  static void config_screen_layout_widgets(struct config_screen *screen)
 
 	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 (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);
 	}
 
 	widget_move(widget_button_base(screen->widgets.ok_b),
@@ -1020,22 +1020,22 @@  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);
 	}
 
 	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);
diff --git a/utils/hooks/30-add-offb.c b/utils/hooks/30-add-offb.c
index e5947ca..eca9d13 100644
--- a/utils/hooks/30-add-offb.c
+++ b/utils/hooks/30-add-offb.c
@@ -500,40 +500,43 @@  static char *get_vga_path(struct offb_ctx *ctx)
 
 static int set_stdout(struct offb_ctx *ctx)
 {
-	const char *boot_tty, *ptr;
+	const char *boot_console, *ptr;
 	long unsigned int termno;
 	const fdt32_t *prop;
 	int node, prop_len;
 	char *stdout_path;
 
-	boot_tty = getenv("boot_tty");
-	if (!boot_tty) {
-		fprintf(stderr, "boot_tty not set, using default stdout for boot\n");
+	boot_console = getenv("boot_console");
+	if (!boot_console) {
+		fprintf(stderr, "boot_console not set, using default stdout for boot\n");
 		return 0;
 	}
 
-	if (strstr(boot_tty, "tty") != NULL) {
-		fprintf(stderr, "TTY recognised: %s\n", boot_tty);
+	if (strstr(boot_console, "tty") != NULL) {
+		fprintf(stderr, "TTY recognised: %s\n", boot_console);
 		stdout_path = get_vga_path(ctx);
 	} else {
-		ptr = strstr(boot_tty, "hvc");
+		ptr = strstr(boot_console, "hvc");
 		if (!ptr || strlen(ptr) <= strlen("hvc")) {
-			fprintf(stderr, "Unrecognised console: %s\n", boot_tty);
+			fprintf(stderr, "Unrecognised console: %s\n",
+					boot_console);
 			return 0;
 		}
 		ptr += strlen("hvc");
 		errno = 0;
 		termno = strtoul(ptr, NULL, 0);
 		if (errno) {
-			fprintf(stderr, "Couldn't parse termno from %s\n", boot_tty);
+			fprintf(stderr, "Couldn't parse termno from %s\n",
+					boot_console);
 			return 0;
 		}
-		fprintf(stderr, "HVC recognised: %s\n", boot_tty);
+		fprintf(stderr, "HVC recognised: %s\n", boot_console);
 		stdout_path = get_hvc_path(ctx, termno);
 	}
 
 	if (!stdout_path) {
-		fprintf(stderr, "Couldn't parse %s into a path\n", boot_tty);
+		fprintf(stderr, "Couldn't parse %s into a path\n",
+				boot_console);
 		return -1;
 	}