9 closekeyboard(Keyboardctl *kc)
14 postnote(PNPROC, kc->pid, "kill");
17 /* Drain the channel */
39 threadsetname("kbdproc");
43 while(n>0 && fullrune(buf, n)){
44 m = chartorune(&r, buf);
46 memmove(buf, buf+m, n);
49 m = read(kc->consfd, buf+n, sizeof buf-n);
51 yield(); /* if error is due to exiting, we'll exit here */
52 fprint(2, "keyboard read error: %r\n");
60 initkeyboard(char *file)
65 kc = mallocz(sizeof(Keyboardctl), 1);
70 kc->file = strdup(file);
71 kc->consfd = open(file, ORDWR|OCEXEC);
72 t = malloc(strlen(file)+16);
73 if(kc->consfd<0 || t==nil){
78 sprint(t, "%sctl", file);
79 kc->ctlfd = open(t, OWRITE|OCEXEC);
81 fprint(2, "initkeyboard: can't open %s: %r\n", t);
87 if(ctlkeyboard(kc, "rawon") < 0){
88 fprint(2, "initkeyboard: can't turn on raw mode on %s: %r\n", t);
93 kc->c = chancreate(sizeof(Rune), 20);
94 chansetname(kc->c, "kbdc");
95 proccreate(_ioproc, kc, 4096);
100 ctlkeyboard(Keyboardctl *kc, char *m)
102 return write(kc->ctlfd, m, strlen(m));