harden ipc and frontend recovery

This commit is contained in:
2026-08-11 19:34:47 +09:00
parent 4bfb659b6d
commit 9dc116a035
14 changed files with 495 additions and 245 deletions

View File

@@ -308,14 +308,24 @@ init(void)
im.l = getlang(LangEN);
}
static void
imhandlekey(Keyreq *kr)
{
Keyres res;
sclear(&res.commit);
sclear(&res.preedit);
res.eaten = keystroke(kr->ks, kr->mod, &res.commit);
if(kr->want)
res.preedit = im.pre;
chansend(kr->reply, &res);
}
void
imthread(void*)
{
Keyreq kr;
Dictres res;
Str com;
uchar out[256];
int n, len, r;
Alt alts[] = {
{keyc, &kr, CHANRCV, nil},
{dictresc, &res, CHANRCV, nil},
@@ -327,24 +337,7 @@ imthread(void*)
for(;;){
switch(alt(alts)){
case 0:
sclear(&com);
r = keystroke(kr.ks, kr.mod, &com);
out[0] = r;
out[1] = 0;
n = 2;
if(com.n > 0){
len = stoutf(&com, (char*)(out+2), sizeof(out)-2);
out[1] = len;
n += len;
}
if(kr.want){
len = im.pre.n > 0 ?
stoutf(&im.pre, (char*)(out+n+1),
sizeof(out)-n-1) : 0;
out[n] = len;
n += 1 + len;
}
write(kr.fd, out, n);
imhandlekey(&kr);
break;
case 1:
if(scmp(&res.key, &im.pre) == 0){
@@ -385,4 +378,3 @@ mapinit(char *dir)
langs[i].map = trieopen(path);
}
}