diff options
author | Imre Deak <imre.deak@intel.com> | 2014-05-12 13:29:49 +0300 |
---|---|---|
committer | Imre Deak <imre.deak@intel.com> | 2014-05-12 13:36:40 +0300 |
commit | 63746417e25b8e9efbeb6021c768695740849a18 (patch) | |
tree | 782b8ecd2b62f4a7d5b29d9fe3dda85c38cec8dc /tests/testdisplay.c | |
parent | d848a36545eec43760de7e34a57a796182358087 (diff) |
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 <imre.deak@intel.com>
Diffstat (limited to 'tests/testdisplay.c')
-rw-r--r-- | tests/testdisplay.c | 23 |
1 files changed, 11 insertions, 12 deletions
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 <stdlib.h> #include <signal.h> +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; } |