From d3a699a8fb86a03d4ef44594a8ff7e9a5ec8ea16 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sat, 13 Mar 2021 12:33:53 -0500 Subject: [PATCH 1/3] Have autocons attempt sizing of serial console If a terminal is open during autocons, that terminal will be the size of the console. Otherwise, fallback to 100x31. --- confluent_osdeploy/utils/autocons.c | 63 +++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/confluent_osdeploy/utils/autocons.c b/confluent_osdeploy/utils/autocons.c index 018f43b5..75389af9 100644 --- a/confluent_osdeploy/utils/autocons.c +++ b/confluent_osdeploy/utils/autocons.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -20,20 +21,29 @@ int main(int argc, char* argv[]) { struct termios tty; + struct termios tty2; + struct winsize ws; + unsigned width, height; int ttyf; - int spcr; + int tmpi; int currspeed; + int flags; speed_t cspeed; char buff[128]; + int bufflen; + fd_set set; + struct timeval timeout; char* offset; uint64_t address; - spcr = open("/sys/firmware/acpi/tables/SPCR", O_RDONLY); - if (spcr < 0) { + bufflen = 0; + tmpi = open("/sys/firmware/acpi/tables/SPCR", O_RDONLY); + if (tmpi < 0) { exit(0); } - if (read(spcr, buff, 80) < 80) { + if (read(tmpi, buff, 80) < 80) { exit(0); } + close(tmpi); if (buff[8] != 2) exit(0); //revision 2 if (buff[36] != 0) exit(0); //16550 only if (buff[40] != 1) exit(0); //IO only @@ -69,12 +79,49 @@ int main(int argc, char* argv[]) { } tcgetattr(ttyf, &tty); if (cspeed) { - cfsetospeed(&tty, B115200); - cfsetispeed(&tty, B115200); + cfsetospeed(&tty, cspeed); + cfsetispeed(&tty, cspeed); } + printf("%s\n", buff); + tcgetattr(ttyf, &tty2); + cfmakeraw(&tty2); + tcsetattr(ttyf, TCSANOW, &tty2); + flags = fcntl(ttyf, F_GETFL, 0); + fcntl(ttyf, F_SETFL, flags | O_NONBLOCK); + while (read(ttyf, buff, 64) > 0) { + // Drain any pending reads + } + timeout.tv_sec = 0; + timeout.tv_usec = 500000; + FD_ZERO(&set); + FD_SET(ttyf, &set); + write(ttyf, "\0337\033[999;999H\033[6n\0338", 18); + while (select(ttyf + 1, &set, NULL, NULL, &timeout) > 0) { + if ((tmpi = read(ttyf, buff + bufflen, 127 - bufflen)) < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + continue; + } else { + break; + } + } + bufflen += tmpi; + buff[bufflen] = 0; + if (strchr(buff, 'R')) { + break; + } + } + fcntl(ttyf, F_SETFL, flags); + ws.ws_xpixel = 0; + ws.ws_ypixel = 0; + if (sscanf(buff, "\033[%u;%uR", &height, &width) == 2) { + ws.ws_col = width; + ws.ws_row = height; + } else { + ws.ws_col = 100; + ws.ws_row = 31; + } + ioctl(ttyf, TIOCSWINSZ, &ws); tcsetattr(ttyf, TCSANOW, &tty); ioctl(ttyf, TIOCCONS, 0); - printf("%s\n", buff); - } From 7da0dfa0bb6c7ed619bc4068ca4e2be8d17fc2db Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sat, 13 Mar 2021 12:47:48 -0500 Subject: [PATCH 2/3] Have tmux keep reattaching If someone accidentally detaches, then intervene and reattach. --- .../genesis/initramfs/opt/confluent/bin/rungenesis | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis b/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis index e18aef2c..baa68fdd 100644 --- a/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis +++ b/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis @@ -8,14 +8,14 @@ if ! grep console= /proc/cmdline >& /dev/null; then echo $autocons > /tmp/01-autocons.devnode if [ ! -z "$autocons" ]; then echo "Using $(cat /tmp/01-autocons.conf)" - tmux a <> $autocons >&0 2>&1 & - TERM=linux tmux a <> /dev/tty1 >&0 2>&1 & + (while :; do tmux a <> $autocons >&0 2>&1; done) & + (while :; do TERM=linux tmux a <> /dev/tty1 >&0 2>&1; done) & else - tmux a <> /dev/console >&0 2>&1 & + (while :; do tmux a <> /dev/console >&0 2>&1; done) & fi else - tmux a <> /dev/console >&0 2>&1 & - TERM=linux tmux a <> /dev/tty1 >&0 2>&1 & + (while :; do tmux a <> /dev/console >&0 2>&1; done) & + (while :; do TERM=linux tmux a <> /dev/tty1 >&0 2>&1; done) & fi echo -n "udevd: " /usr/lib/systemd/systemd-udevd --daemon From df328d68128eadbadc01225bc83291983b70ddc1 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sat, 13 Mar 2021 12:49:26 -0500 Subject: [PATCH 3/3] Have tty2 also run a shell Some may find switching VTs to be more intuitive than tmux session management. Provide one extra on tty2 for such a scenario. --- .../genesis/initramfs/opt/confluent/bin/rungenesis | 1 + 1 file changed, 1 insertion(+) diff --git a/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis b/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis index baa68fdd..8a193e22 100644 --- a/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis +++ b/confluent_osdeploy/genesis/initramfs/opt/confluent/bin/rungenesis @@ -17,6 +17,7 @@ else (while :; do tmux a <> /dev/console >&0 2>&1; done) & (while :; do TERM=linux tmux a <> /dev/tty1 >&0 2>&1; done) & fi +(while :; do TERM=linux tmux <> /dev/tty2 >&0 2>&1; done) & echo -n "udevd: " /usr/lib/systemd/systemd-udevd --daemon echo -n "Loading drivers..."