summaryrefslogtreecommitdiff
path: root/sys/src/libdraw
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-05-19 20:04:47 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2015-05-19 20:04:47 +0200
commit6198954859caa0de243756291c8dad75b71dcaee (patch)
treef6fd8819a7196dc09d371961021bc25f972d8822 /sys/src/libdraw
parent8f8c2d67796e8da8a3f8d3e86849b07182a96697 (diff)
libdraw: don't loop forever when getting eof on /dev/cons in keyboard ioproc
Diffstat (limited to 'sys/src/libdraw')
-rw-r--r--sys/src/libdraw/keyboard.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/sys/src/libdraw/keyboard.c b/sys/src/libdraw/keyboard.c
index 9f3b29587..a86a24b39 100644
--- a/sys/src/libdraw/keyboard.c
+++ b/sys/src/libdraw/keyboard.c
@@ -19,7 +19,7 @@ static
void
_ioproc(void *arg)
{
- int m, n;
+ int m, n, nerr;
char buf[20];
Rune r;
Keyboardctl *kc;
@@ -27,18 +27,27 @@ _ioproc(void *arg)
kc = arg;
threadsetname("kbdproc");
n = 0;
-loop:
+ nerr = 0;
while(kc->consfd >= 0){
+ m = read(kc->consfd, buf+n, sizeof buf-n);
+ if(m <= 0){
+ yield(); /* if error is due to exiting, we'll exit here */
+ if(kc->consfd < 0)
+ break;
+ fprint(2, "keyboard: short read: %r\n");
+ if(m<0 || ++nerr>10)
+ threadexits("read error");
+ continue;
+ }
+ nerr = 0;
+ n += m;
while(n>0 && fullrune(buf, n)){
m = chartorune(&r, buf);
n -= m;
memmove(buf, buf+m, n);
if(send(kc->c, &r) < 0)
- goto loop;
+ break;
}
- if((m = read(kc->consfd, buf+n, sizeof buf-n)) <= 0)
- goto loop;
- n += m;
}
chanfree(kc->c);
free(kc->file);