From 9f4507969377565d94c89eb4386391de89f37aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20S=C5=82omi=C5=84ski?= Date: Sat, 11 Jun 2022 15:50:55 +0200 Subject: [PATCH] Fix keyboard detection from open file descriptors If any of the file descriptors turns out to be a keyboard, we shouldn't fail with the error that no keyboard was found. --- fbdoom/i_input_tty.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fbdoom/i_input_tty.c b/fbdoom/i_input_tty.c index e66e17b..7e09b4a 100644 --- a/fbdoom/i_input_tty.c +++ b/fbdoom/i_input_tty.c @@ -280,6 +280,7 @@ static int kbd_init(void) char *files_to_try[] = {"/dev/tty", "/dev/console", NULL}; int i; int flags; + int found = 0; /* First we need to find a file descriptor that represents the system's keyboard. This should be /dev/tty, /dev/console, @@ -293,6 +294,7 @@ static int kbd_init(void) /* See if this is valid for our purposes. */ if (tty_is_kbd(kb)) { printf("Using keyboard on %s.\n", files_to_try[i]); + found = 1; break; } close(kb); @@ -303,8 +305,14 @@ static int kbd_init(void) might point to a console. This is not especially likely. */ if (files_to_try[i] == NULL) { for (kb = 0; kb < 3; kb++) { - if (tty_is_kbd(i)) break; + if (tty_is_kbd(i)) { + found = 1; + break; + } } + } + + if (!found) { printf("Unable to find a file descriptor associated with "\ "the keyboard.\n" \ "Perhaps you're not using a virtual terminal?\n");