From dceccaf1695a69227947501102977bbac240977b Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 28 Oct 2013 23:32:57 +0100 Subject: getch2: assume EOF when input file descriptor is invalid When starting mpv with nohup, file descriptor 0 seems to be invalid for some reason. (I'm not quite sure why it should be... /proc/pid/fd/0 seems to indicate it's just /dev/null, and using /dev/null explicitly shows that it works just fine.) select() will always immediately return, and this causes mpv to burn CPU without reason. Fix this by treating it as EOF when read() returns EBADF. Also add EINVAL to this condition, because it seems like a good idea. --- osdep/getch2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'osdep') diff --git a/osdep/getch2.c b/osdep/getch2.c index 13eb47bc29..8b87e79c76 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #ifdef HAVE_TERMIOS @@ -366,8 +367,10 @@ bool getch2(struct input_ctx *input_ctx) * happen if the terminal state change done in getch2_enable() * works. */ - if (retval < 1) - return retval; + if (retval == 0) + return false; + if (retval == -1) + return errno != EBADF && errno != EINVAL; getch2_len += retval; while (getch2_pos < getch2_len) { -- cgit v1.2.3