shithub: qk2

Download patch

ref: 6cf736d1ac86a82f8cb947abd1f6b007af4ff046
parent: 11eabae817604b898a02bc4db0b0aaba23d9648d
author: qwx <>
date: Fri Jun 1 08:28:16 EDT 2018

in: minor cleanup

--- a/in.c
+++ b/in.c
@@ -255,14 +255,21 @@
 	Rune r;
 	Kev ev;
 
-	if(threadsetgrp(THin) < 0)
-		sysfatal("kproc:threadsetgrp: %r");
 	if((fd = open("/dev/kbd", OREAD)) < 0)
-		sysfatal("open /dev/kbd: %r");
-
-	kdown[0] = kdown[1] = 0;
-	while((n = read(fd, buf, sizeof buf)) > 0){
-		buf[n-1] = 0;
+		sysfatal("kproc: %r");
+	kdown[0] = kdown[1] = buf[0] = 0;
+	for(;;){
+		if(buf[0] != 0){
+			n = strlen(buf)+1;
+			memmove(buf, buf+n, sizeof(buf)-n);
+		}
+		if(buf[0] == 0){
+			n = read(fd, buf, sizeof(buf)-1);
+			if(n <= 0)
+				break;
+			buf[n-1] = 0;
+			buf[n] = 0;
+		}
 		switch(*buf){
 		case 'c':
 		default:
@@ -276,7 +283,7 @@
 						ev.key = k;
 						ev.down = true;
 						if(send(kchan, &ev) < 0)
-							sysfatal("kproc:nbsend: %r\n");
+							goto end;
 					}
 				}
 			}
@@ -290,7 +297,7 @@
 						ev.key = k;
 						ev.down = false;
 						if(send(kchan, &ev) < 0)
-							sysfatal("mproc:nbsend: %r\n");
+							goto end;
 					}
 				}
 			}
@@ -298,8 +305,7 @@
 		}
 		strcpy(kdown, buf);
 	}
-	fprint(2, "kproc: %r\n");
-	close(fd);
+end:;
 }
 
 static void
@@ -309,16 +315,13 @@
 	char buf[1+5*12];
 	Mouse m;
 
-	if(threadsetgrp(THin) < 0)
-		sysfatal("mproc:threadsetgrp: %r");
 	if((fd = open("/dev/mouse", ORDWR)) < 0)
-		sysfatal("open /dev/mouse: %r");
-
+		sysfatal("mproc: %r");
 	for(;;){
 		if((n = read(fd, buf, sizeof buf)) != 1+4*12){
-			fprint(2, "mproc:read: bad count %d not 49: %r\n", n);
 			if(n < 0 || ++nerr > 10)
 				break;
+			fprint(2, "mproc:read: bad count %d not 49: %r\n", n);
 			continue;
 		}
 		nerr = 0;
@@ -337,13 +340,11 @@
 			m.buttons = atoi(buf+1+2*12);
 			m.msec = atoi(buf+1+3*12);
 			if(nbsend(mchan, &m) < 0)
-				sysfatal("mproc:nbsend: %r\n");
+				goto end;
 			break;
 		}
 	}
-	fprint(2, "mproc: %r\n");
-	IN_Grabm(0);
-	close(fd);
+end:;
 }
 
 static void
@@ -380,8 +381,6 @@
 	int n;
 	char s[256];
 
-	threadsetgrp(THin);
-
 	if((iop = pipe(pfd)) < 0)
 		sysfatal("iproc:pipe: %r");
 	for(;;){
@@ -400,21 +399,12 @@
 void
 IN_Shutdown(void)
 {
-	qlock(&killock);	/* there can be only one */
 	IN_Grabm(0);
-	threadkillgrp(THin);
 	iop = -1;
 	close(pfd[0]);
 	close(pfd[1]);
-	if(kchan != nil){
-		chanfree(kchan);
-		kchan = nil;
-	}
-	if(mchan != nil){
-		chanfree(mchan);
-		mchan = nil;
-	}
-	qunlock(&killock);
+	chanfree(kchan);
+	chanfree(mchan);
 }
 
 void
--- a/sys.c
+++ b/sys.c
@@ -400,7 +400,7 @@
 croak(void *, char *note)
 {
 	if(!strncmp(note, "sys:", 4)){
-		IN_Shutdown();
+		IN_Grabm(0);
 		shutsnd();
 		NET_Shutdown();
 	}