[Bug 794591] gst-play-1.0 leaves stdin in non-blocking mode
GStreamer (GNOME Bugzilla)
bugzilla at gnome.org
Thu Mar 22 16:51:31 UTC 2018
https://bugzilla.gnome.org/show_bug.cgi?id=794591
--- Comment #4 from Antonio Ospite <ao2 at ao2.it> ---
(In reply to Tim-Philipp Müller from comment #3)
[...]
> Do we actually need to set stdin to non-blocking in the first place? We hook
> into the glib event loop to pick up input, so I don't know if there was a
> reason for that or not.
I verified that just removing the code about O_NONBLOCK breaks interactive
mode.
I don't know glib internals but, assuming it select/polls the fd, the terminal
still needs to be configured so that the data gets read() as soon as it
arrives.
Clearing ICANON is not enough for that to happen.
Setting the fd to non-block achieves the desired effect.
However from man termios it turns out the proper way to achieve the polling
read() with the terminal in raw mode is to set c_cc[VMIN] and c_cc[VTIME] to 0
in struct termios.
Also in Advanced Programming in the Unix Environment 2nd edition by Richard
Stevens, Section 4.5.9, it is strongly recommended to set VMIN and VTIME
explicitly when clearing ICANON:
The subscripts VMIN and VTIME of the c_cc array hold MIN and TIME. As
those positions may be the same ones used by VEOF and VEOL, make sure
you set MIN and TIME explicitly or you might get whatever the current
EOF and EOL characters work out to, which will cause very strange
results. If you ever find a process getting input on every fourth
character typed, this is probably what’s happened. (Ctrl-d, the usual
EOF character, is 4.)
So let's just do that and with VMIN and VTIME set to 0, using O_NONBLOCK is not
needed anymore.
As a side note, using O_NONBLOCK is even discouraged in some cases, from the
same section of the book:
The standards don’t specify exactly what happens if O_NONBLOCK is set
and MIN and/or TIME are nonzero. O_NONBLOCK may have precedence
(causing an immediate return if no characters are available), or
MIN/TIME may have precedence. To avoid this uncertainty, you should
not set O_NONBLOCK when ICANON is clear.
This does not apply here because we'll just set the values to 0, but I take
this as a hint that O_NONBLOCK is not the right mechanism for terminals, even
if sometimes it happens to have the desired effect.
New patch coming up.
Ciao,
Antonio
--
You are receiving this mail because:
You are the QA Contact for the bug.
You are the assignee for the bug.
More information about the gstreamer-bugs
mailing list