8 closekeyboard(Keyboardctl *kc)
14 kc->consfd = kc->ctlfd = -1;
28 threadsetname("kbdproc");
31 while(kc->consfd >= 0){
32 m = read(kc->consfd, buf+n, sizeof buf-n);
34 yield(); /* if error is due to exiting, we'll exit here */
37 fprint(2, "keyboard: short read: %r\n");
39 threadexits("read error");
44 while(n>0 && fullrune(buf, n)){
45 m = chartorune(&r, buf);
47 memmove(buf, buf+m, n);
48 if(send(kc->c, &r) < 0)
58 initkeyboard(char *file)
63 kc = mallocz(sizeof(Keyboardctl), 1);
68 kc->file = strdup(file);
69 kc->consfd = open(file, ORDWR|OCEXEC);
70 t = malloc(strlen(file)+16);
71 if(kc->consfd<0 || t==nil){
76 sprint(t, "%sctl", file);
77 kc->ctlfd = open(t, OWRITE|OCEXEC);
79 fprint(2, "initkeyboard: can't open %s: %r\n", t);
85 if(ctlkeyboard(kc, "rawon") < 0){
86 fprint(2, "initkeyboard: can't turn on raw mode on %s: %r\n", t);
91 kc->c = chancreate(sizeof(Rune), 20);
92 kc->pid = proccreate(_ioproc, kc, 4096);
97 ctlkeyboard(Keyboardctl *kc, char *m)
99 return write(kc->ctlfd, m, strlen(m));