If multiple consoles are found from the sysfs file, cttyhack will fail:

        cttyhack: can't open '/dev/tty0 ttyS0': No such file or directory

In such cases take the last one as the kernel will use that one for
/dev/console.

Signed-off-by: Aaro Koskinen <[email protected]>
---
 shell/cttyhack.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/shell/cttyhack.c b/shell/cttyhack.c
index 6ff8674..b2614b5 100644
--- a/shell/cttyhack.c
+++ b/shell/cttyhack.c
@@ -128,10 +128,19 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv)
                        int s = open_read_close("/sys/class/tty/console/active",
                                console + 5, sizeof(console) - 5);
                        if (s > 0) {
+                               char *last;
                                /* found active console via sysfs (Linux 
2.6.38+)
                                 * sysfs string looks like "ttyS0\n" so zap the 
newline:
                                 */
                                console[4 + s] = '\0';
+                               /* if there are multiple consoles, take the last
+                                * one:
+                                */
+                               last = strrchr(console + 5, ' ');
+                               if (last != NULL)
+                                       memmove(console + 5,
+                                               last + 1,
+                                               s - (last - (console + 5)) - 1);
                                break;
                        }
 
-- 
1.7.2.5

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to