summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphintuka <phintuka>2006-09-19 00:56:13 +0000
committerphintuka <phintuka>2006-09-19 00:56:13 +0000
commit1a42c32cb6903b3285ce6c3e3c0e2be428b6ee64 (patch)
treec830affcadf807c0818bd43c3818778758d64f81
parent8597f66ac9357bdeab28bf387300e9c549e75e07 (diff)
downloadxineliboutput-1a42c32cb6903b3285ce6c3e3c0e2be428b6ee64.tar.gz
xineliboutput-1a42c32cb6903b3285ce6c3e3c0e2be428b6ee64.tar.bz2
Fixed busy loop when stdin not open/available
(read_key returns now error if read() returns 0)
-rw-r--r--xine_frontend_main.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/xine_frontend_main.c b/xine_frontend_main.c
index 21be5c5c..4b1670ae 100644
--- a/xine_frontend_main.c
+++ b/xine_frontend_main.c
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: xine_frontend_main.c,v 1.13 2006-09-01 15:14:30 phintuka Exp $
+ * $Id: xine_frontend_main.c,v 1.14 2006-09-19 00:56:13 phintuka Exp $
*
*/
@@ -43,20 +43,29 @@ volatile int terminate_key_pressed = 0;
static int read_key(void)
{
- /* from vdr, remote.c */
+ unsigned char ch;
+ int err;
struct pollfd pfd;
pfd.fd = STDIN_FILENO;
pfd.events = POLLIN;
- if(poll(&pfd, 1, 50) == 1) {
- unsigned char ch = 0;
- int r = read(STDIN_FILENO, &ch, 1);
- if (r == 1)
+
+ errno = 0;
+ if(1 == (err=poll(&pfd, 1, 50))) {
+
+ if (1 == (err = read(STDIN_FILENO, &ch, 1)))
return (int)ch;
- if (r < 0) {
- LOGERR("read_key: read failed");
- return -2;
- }
+
+ if (err < 0)
+ LOGERR("read_key: read(stdin) failed");
+ else
+ LOGERR("read_key: read(stdin) failed: no stdin");
+ return -2;
+
+ } else if(err < 0) {
+ LOGERR("read_key: poll(stdin) failed");
+ return -2;
}
+
return -1;
}