diff options
author | Mathew McBride <matt@traverse.com.au> | 2021-03-05 00:54:15 +0000 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2021-03-07 23:46:27 +0000 |
commit | 2cfc26f8456a4d5ba3836c914a742f3d00bad781 (patch) | |
tree | e79983cc45db11a70477b8837a628a2807dc1132 /utils | |
parent | 945d0d79cbef1f0dd9958f409548d48ce783d933 (diff) | |
download | procd-2cfc26f8456a4d5ba3836c914a742f3d00bad781.tar.gz |
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 <matt@traverse.com.au>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/utils.c | 22 | ||||
-rw-r--r-- | utils/utils.h | 1 |
2 files changed, 23 insertions, 0 deletions
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); |