diff --git a/src/include/tio/tty.h b/src/include/tio/tty.h index 6226263..4612ebe 100644 --- a/src/include/tio/tty.h +++ b/src/include/tio/tty.h @@ -42,6 +42,7 @@ void stdout_configure(void); void stdout_restore(void); void stdin_configure(void); void stdin_restore(void); +void tty_check(void); void tty_configure(void); int tty_connect(void); void tty_wait_for_device(void); diff --git a/src/main.c b/src/main.c index 83c060a..28fd8aa 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,9 @@ int main(int argc, char *argv[]) /* Parse options */ parse_options(argc, argv); + /* Check tty */ + tty_check(); + /* Configure tty device */ tty_configure(); diff --git a/src/tty.c b/src/tty.c index bee6f9f..e3d6c2b 100644 --- a/src/tty.c +++ b/src/tty.c @@ -276,6 +276,15 @@ void stdout_restore(void) tcsetattr(STDOUT_FILENO, TCSANOW, &stdout_old); } +void tty_check(void) +{ + if (access(option.tty_device, R_OK) != 0) + { + error_printf("Could not access the TTY (%s)", strerror(errno)); + exit(EXIT_FAILURE); + } +} + void tty_configure(void) { bool token_found = true; @@ -504,10 +513,6 @@ void tty_wait_for_device(void) error_printf("select() failed (%s)", strerror(errno)); exit(EXIT_FAILURE); } - - /* Test for accessible device file */ - if (access(option.tty_device, R_OK) == 0) - return; } }