Adds eshutdown(2) to allow programs to stop event processing before exiting. There is currently no way for programs using event(2) to stop event processing. Device files and memory are held by the library. This prevents programs using event(2) from returning to console mode cleanly without exiting. This patch adds eshutdown(2) to provide that function. Existing programs using event(2) should not be affected by this change. I have recompiled and run clock(1) and tweak(1) for testing, both of which behave unchanged. Notes: Wed Mar 19 15:07:39 EDT 2008 geoff Please (re)read style(6) and edit your code to conform, then resubmit this patch. Thanks. Reference: /n/sources/patch/sorry/eshutdown Date: Sat Mar 15 19:14:56 CET 2008 Signed-off-by: stefanha@gmail.com Reviewed-by: geoff --- /sys/include/event.h Sat Mar 15 19:13:58 2008 +++ /sys/include/event.h Sat Mar 15 19:13:54 2008 @@ -44,6 +44,7 @@ * Events */ extern void einit(ulong); +extern void eshutdown(void); extern ulong estart(ulong, int, int); extern ulong estartfn(ulong, int, int, int (*fn)(int, Event*, uchar*, int)); extern ulong etimer(ulong, int); --- /sys/src/libdraw/event.c Sat Mar 15 19:14:12 2008 +++ /sys/src/libdraw/event.c Sat Mar 15 19:14:08 2008 @@ -10,7 +10,7 @@ struct Slave { int pid; - Ebuf *head; /* ueue of messages for this descriptor */ + Ebuf *head; /* queue of messages for this descriptor */ Ebuf *tail; int (*fn)(int, Event*, uchar*, int); }; @@ -37,6 +37,8 @@ static int enote(void *, char *); static int mousefd; static int cursorfd; +static int consfd; +static int ctlfd; static Ebuf* @@ -228,13 +230,15 @@ void einit(ulong keys) { - int ctl, fd; + int firstinit; char buf[256]; + firstinit = (parentpid == 0); parentpid = getpid(); if(pipe(epipe) < 0) drawerror(display, "events: einit pipe"); - atexit(ekill); + if(firstinit) + atexit(ekill); atnotify(enote, 1); snprint(buf, sizeof buf, "%s/mouse", display->devdir); mousefd = open(buf, ORDWR|OCEXEC); @@ -246,17 +250,17 @@ drawerror(display, "einit: can't open cursor\n"); if(keys&Ekeyboard){ snprint(buf, sizeof buf, "%s/cons", display->devdir); - fd = open(buf, OREAD); - if(fd < 0) + consfd = open(buf, OREAD); + if(consfd < 0) drawerror(display, "events: can't open console"); snprint(buf, sizeof buf, "%s/consctl", display->devdir); - ctl = open("/dev/consctl", OWRITE|OCEXEC); - if(ctl < 0) + ctlfd = open("/dev/consctl", OWRITE|OCEXEC); + if(ctlfd < 0) drawerror(display, "events: can't open consctl"); - write(ctl, "rawon", 5); + write(ctlfd, "rawon", 5); for(Skeyboard=0; Ekeyboard & ~(1< 0){ + wt = wait(); + if(!wt) + break; + for(i=0; ipid){ + nalive--; + } + } + free(wt); + } + for(i=0; inext; + free(eb); + } + memset(&eslave[i], 0, sizeof(eslave[i])); + } + nslave = 0; + Skeyboard = -1; + Smouse = -1; + Stimer = -1; + write(ctlfd, "rawoff", 6); + close(ctlfd); + ctlfd = -1; + close(consfd); + consfd = -1; + close(cursorfd); + cursorfd = -1; + close(mousefd); + mousefd = -1; +} + +void +eshutdown(void) +{ + _eshutdown(0); +} + +static void extract(void) { Slave *s; @@ -372,22 +439,15 @@ } return 0; } - close(epipe[0]); - epipe[0] = -1; - close(epipe[1]); - epipe[1] = -1; - for(i=0; i