tools: play: fix leaving STDIN in non-blocking mode after exit

gst-play-1.0 sets STDIN to non-blocking mode to have the input
characters read as soon as they arrive.

However, when gst_play_kb_set_key_handler() gets called from
restore_terminal() it forgets to restore the STDIN blocking status.

This can result in broken behavior for cli command executed in the same
terminal after gst-play-1.0 exited.

It turns out that putting STDIN in non-blocking mode is not even the
proper way to achieve the desired effect, instead VMIN and VTIME in
struct termios should be set to 0.

Let's do that, and don't mess with the STDIN blocking mode now that it's
not necessary.

https://bugzilla.gnome.org/show_bug.cgi?id=794591
This commit is contained in:
Antonio Ospite 2018-03-22 11:12:20 +01:00 committed by Tim-Philipp Müller
parent dc527cac62
commit cfc1be0d61

View file

@ -71,7 +71,6 @@ gboolean
gst_play_kb_set_key_handler (GstPlayKbFunc kb_func, gpointer user_data) gst_play_kb_set_key_handler (GstPlayKbFunc kb_func, gpointer user_data)
{ {
GIOChannel *ioc; GIOChannel *ioc;
int flags;
if (!isatty (STDIN_FILENO)) { if (!isatty (STDIN_FILENO)) {
GST_INFO ("stdin is not connected to a terminal"); GST_INFO ("stdin is not connected to a terminal");
@ -106,6 +105,8 @@ gst_play_kb_set_key_handler (GstPlayKbFunc kb_func, gpointer user_data)
/* Echo off, canonical mode off, extended input processing off */ /* Echo off, canonical mode off, extended input processing off */
new_settings = term_settings; new_settings = term_settings;
new_settings.c_lflag &= ~(ECHO | ICANON | IEXTEN); new_settings.c_lflag &= ~(ECHO | ICANON | IEXTEN);
new_settings.c_cc[VMIN] = 0;
new_settings.c_cc[VTIME] = 0;
if (tcsetattr (STDIN_FILENO, TCSAFLUSH, &new_settings) != 0) { if (tcsetattr (STDIN_FILENO, TCSAFLUSH, &new_settings) != 0) {
g_warning ("Could not set terminal state"); g_warning ("Could not set terminal state");
@ -117,10 +118,6 @@ gst_play_kb_set_key_handler (GstPlayKbFunc kb_func, gpointer user_data)
ioc = g_io_channel_unix_new (STDIN_FILENO); ioc = g_io_channel_unix_new (STDIN_FILENO);
/* make non-blocking */
flags = g_io_channel_get_flags (ioc);
g_io_channel_set_flags (ioc, flags | G_IO_FLAG_NONBLOCK, NULL);
io_watch_id = g_io_add_watch_full (ioc, G_PRIORITY_DEFAULT, G_IO_IN, io_watch_id = g_io_add_watch_full (ioc, G_PRIORITY_DEFAULT, G_IO_IN,
(GIOFunc) gst_play_kb_io_cb, user_data, NULL); (GIOFunc) gst_play_kb_io_cb, user_data, NULL);
g_io_channel_unref (ioc); g_io_channel_unref (ioc);