From fdba43ea0af4bee99676019cc818d982e969e9f9 Mon Sep 17 00:00:00 2001 From: Daniel Mentz Date: Fri, 14 Apr 2023 15:13:19 -0700 Subject: [PATCH] Fix oneit sysfs console autodetection oneit appears to have made the assumption that /sys/class/tty/console/active provides a list of console names separated by newline characters. It turned out, though, that individual names are separated by space characters with a newline character at the very end of the list. We previously observed the following error message: oneit: /dev/ttynull ttyS0: No such file or directory --- toys/other/oneit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/toys/other/oneit.c b/toys/other/oneit.c index d154f582..13f58078 100644 --- a/toys/other/oneit.c +++ b/toys/other/oneit.c @@ -73,12 +73,13 @@ void oneit_main(void) // Autodetect console from sysfs if no -c memcpy(toybuf, "/dev/", 5); if (!TT.c && (TT.c = readfile("/sys/class/tty/console/active", ss, 4096))) { - // Remove null terminator, take last entry + // Take last entry, remove newline terminator for (;;) { - if (!(ss = strchr(TT.c, '\n'))) break; + if (!(ss = strchr(TT.c, ' '))) break; if (!ss[1]) *ss = 0; else TT.c = ++ss; } + if (ss = strchr(TT.c, '\n')) ss[1] = 0; // Ensure /dev prefix strstart(&TT.c, "/dev/"); memmove(toybuf+5, TT.c, strlen(TT.c)); -- 2.39.2