ref: 893c8afdd86aa3c4840f996bfe8dbb25587bc0ea
parent: 5044a571e9a5a8e952a1f496859a38635497f43f
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Nov 4 12:46:47 EST 2020
exit more cleanly
--- a/mbox.c
+++ b/mbox.c
@@ -75,9 +75,12 @@
while(1){
ev = emalloc(sizeof(Event));
if(winevent(&mbox, ev) == -1)
- threadexitsall(nil);
+ break;
sendp(mbox.event, ev);
}
+ closeioproc(mbox.io);
+ sendp(mbox.event, nil);
+ threadexits(nil);
}
static int
@@ -612,11 +615,27 @@
static void
mbquit(char **, int)
{
+ Event *e;
+ Ioproc *io;
+
if(mbox.nopen > 0){
fprint(2, "Del: %d open messages\n", mbox.nopen);
return;
}
+
+ /*
+ * Do a bit of a dance to ensure that we don't
+ * try to read from the ioproc after we close
+ * it while exiting.
+ */
+ io = mbox.io;
+ mbox.io = nil;
+
winclose(&mbox);
+ iointerrupt(io);
+ while((e = recvp(mbox.event)) != nil)
+ free(e);
+ closeioproc(io);
threadexitsall(nil);
}
--- a/win.c
+++ b/win.c
@@ -32,8 +32,10 @@
n = 0;
while('0'<=(c=Bgetc(f)) && c<='9')
n = n*10+(c-'0');
- if(c != ' ')
- sysfatal("event number syntax: %c(%d)", c, c);
+ if(c != ' '){
+ werrstr("event number syntax: %c", c);
+ return -1;
+ }
return n;
}
@@ -63,8 +65,10 @@
e->q1 = evgetnum(w->event);
e->flags = evgetnum(w->event);
e->ntext = evgetdata(w->event, e);
- if(Bgetc(w->event) != '\n')
- sysfatal("unterminated message");
+ if(Bgetc(w->event) != '\n'){
+ werrstr("unterminated message");
+ return -1;
+ }
return e->action;
}