From 2cfc26f8456a4d5ba3836c914a742f3d00bad781 Mon Sep 17 00:00:00 2001 From: Mathew McBride Date: Fri, 5 Mar 2021 00:54:15 +0000 Subject: inittab: detect active console from kernel if no console= specified The default serial console can be set in the device tree using the linux,stdout-path parameter (or equivalent from ACPI). This is important for universal booting (EFI/EBBR) on ARM platforms where the default console can be different (e.g ttyS0 vs ttyAMA0). Signed-off-by: Mathew McBride --- utils/utils.c | 22 ++++++++++++++++++++++ utils/utils.h | 1 + 2 files changed, 23 insertions(+) (limited to 'utils') diff --git a/utils/utils.c b/utils/utils.c index 8d76129..e90feec 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -135,6 +135,28 @@ blobmsg_list_equal(struct blobmsg_list *l1, struct blobmsg_list *l2) return true; } +char *get_active_console(char *out, int len) +{ + char line[CMDLINE_SIZE + 1]; + int fd = open("/sys/class/tty/console/active", O_RDONLY); + ssize_t r = read(fd, line, sizeof(line) - 1); + + close(fd); + + if (r <= 0) + return NULL; + + /* The active file is terminated by a newline which we need to strip */ + char *newline = strtok(line, "\n"); + + if (newline != NULL) { + strncpy(out, newline, len); + return out; + } + + return NULL; +} + char* get_cmdline_val(const char* name, char* out, int len) { char line[CMDLINE_SIZE + 1], *c, *sptr; diff --git a/utils/utils.h b/utils/utils.h index 989ceb2..898bcc4 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -52,6 +52,7 @@ void blobmsg_list_free(struct blobmsg_list *list); bool blobmsg_list_equal(struct blobmsg_list *l1, struct blobmsg_list *l2); void blobmsg_list_move(struct blobmsg_list *list, struct blobmsg_list *src); char *get_cmdline_val(const char *name, char *out, int len); +char *get_active_console(char *out, int len); int patch_fd(const char *device, int fd, int flags); int patch_stdio(const char *device); -- cgit v1.2.1