From 63746417e25b8e9efbeb6021c768695740849a18 Mon Sep 17 00:00:00 2001 From: Imre Deak Date: Mon, 12 May 2014 13:29:49 +0300 Subject: testdisplay: fix restoring termio at exit At normal exit in test_all_modes we don't restore the original termio, since g_io_channel_shutdown() closes the stdin fd and so the following tcsetattr on stdin will fail. We also don't restore the termio at signal exit. Fix both cases by installing an exit hanlder with a dup'ed stdin fd. Signed-off-by: Imre Deak --- tests/testdisplay.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'tests/testdisplay.c') diff --git a/tests/testdisplay.c b/tests/testdisplay.c index 9de7ca08..125e7d2f 100644 --- a/tests/testdisplay.c +++ b/tests/testdisplay.c @@ -71,6 +71,7 @@ #include #include +static int tio_fd; struct termios saved_tio; drmModeRes *resources; @@ -698,9 +699,6 @@ static void __attribute__((noreturn)) usage(char *name) static void cleanup_and_exit(int ret) { close(drm_fd); - - tcsetattr(STDIN_FILENO, TCSANOW, &saved_tio); - exit(ret); } @@ -738,19 +736,22 @@ static void enter_exec_path( char **argv ) free(exec_path); } +static void restore_termio_mode(int sig) +{ + tcsetattr(tio_fd, TCSANOW, &saved_tio); + close(tio_fd); +} + static void set_termio_mode(void) { struct termios tio; - tcgetattr(STDIN_FILENO, &saved_tio); - + tio_fd = dup(STDIN_FILENO); + tcgetattr(tio_fd, &saved_tio); + igt_install_exit_handler(restore_termio_mode); tio = saved_tio; - tio.c_lflag &= ~(ICANON | ECHO); - - tcsetattr(STDIN_FILENO, TCSANOW, &tio); - - return; + tcsetattr(tio_fd, TCSANOW, &tio); } int main(int argc, char **argv) @@ -899,7 +900,5 @@ out_mainloop: out_close: close(drm_fd); - tcsetattr(STDIN_FILENO, TCSANOW, &saved_tio); - return ret; } -- cgit v1.2.3