changed threadprint() by fprint() and added a STACK enum, to avoid stack overflows. Notes: Fri Dec 30 11:34:41 EST 2005 rsc Thanks. I applied this but left the stack size at 8k, which should be way more than enough on Plan 9. Are you seeing stack overflows? Reference: /n/sources/patch/applied/adict-fix2 Date: Fri Dec 30 08:20:30 CET 2005 Reviewed-by: rsc --- /acme/bin/source/adict/adict.c Fri Dec 30 08:06:12 2005 +++ /acme/bin/source/adict/adict.c Fri Dec 30 08:05:01 2005 @@ -5,6 +5,11 @@ #include "win.h" #include "adict.h" +enum +{ + STACK = 16*1024, +}; + char *prog = "adict"; char *lprog = "/bin/adict"; char *xprog = "/bin/dict"; @@ -22,10 +27,12 @@ void usage(void) { - threadprint(2, "usage: %s [-d dictname] [pattern]\n", argv0); + fprint(2, "usage: %s [-d dictname] [pattern]\n", argv0); threadexitsall(nil); } +int mainstacksize = STACK; + void threadmain(int argc, char** argv) { @@ -46,7 +53,7 @@ pattern = pbuffer; strcpy(pattern,argv[0]); if(dict == nil) - dict = "oed"; + dict = "pgw"; break; case 0: break; @@ -89,7 +96,7 @@ rexarg[2] = fpipe; rexarg[3] = c; - proccreate(rexec, rexarg, 8192); + proccreate(rexec, rexarg, STACK); recvul(c); chanfree(c); close(fpipe[1]); @@ -130,7 +137,7 @@ } curaddr[i] = nil; if (i == MAXMATCH) - threadprint(2, "Too many matches!\n"); + fprint(2, "Too many matches!\n"); Bterm(&inbuf); close(fd); @@ -149,7 +156,7 @@ sprint(buffer,"%sh", addr); fd = procrexec(xprog, "-d", dict, "-c", buffer, nil); if (read(fd, pbuffer, 80) > 80) - threadprint(2, "Error in getting addres from dict.\n"); + fprint(2, "Error in getting addres from dict.\n"); else { t = pbuffer; /* remove trailing whitespace, newline */ @@ -182,7 +189,7 @@ sprint(buffer,"%s+a", curone); fd = procrexec(xprog, "-d", dict, "-c", buffer, nil); if (read(fd, abuffer, 80) > 80) - threadprint(2, "Error in getting addres from dict.\n"); + fprint(2, "Error in getting addres from dict.\n"); else { res = abuffer; while (*res != '#') res++; @@ -352,7 +359,7 @@ arg[2] = twin; arg[3] = (void*)wintype; arg[4] = c; - proccreate(vopenwin, arg, 8192); + proccreate(vopenwin, arg, STACK); recvul(c); chanfree(c); } @@ -377,7 +384,7 @@ close(fd[1]); close(fd[0]); procexec(c, prog, args); - threadprint(2, "Remote pipe execution failed: %s %r\n", prog); + fprint(2, "Remote pipe execution failed: %s %r\n", prog); abort(); threadexits(nil); } @@ -396,7 +403,7 @@ c = arg[2]; procexec(c, prog, args); - threadprint(2, "Remote execution failed: %s %r\n", prog); + fprint(2, "Remote execution failed: %s %r\n", prog); abort(); threadexits(nil); } @@ -412,7 +419,7 @@ rexarg[1] = args; rexarg[2] = c; - proccreate(pexec, rexarg, 8192); + proccreate(pexec, rexarg, STACK); recvul(c); chanfree(c); } @@ -503,19 +510,19 @@ wevent(w, &e); switch(e.c2){ default: - /* threadprint(2,"unknown message %c%c\n", e.c1, e.c2); */ + /* fprint(2,"unknown message %c%c\n", e.c1, e.c2); */ break; case 'i': - /* threadprint(2,"'%s' inserted in tag at %d\n", e.b, e.q0);*/ + /* fprint(2,"'%s' inserted in tag at %d\n", e.b, e.q0);*/ break; case 'I': - /* threadprint(2,"'%s' inserted in body at %d\n", e.b, e.q0);*/ + /* fprint(2,"'%s' inserted in body at %d\n", e.b, e.q0);*/ break; case 'd': - /* threadprint(2, "'%s' deleted in tag at %d\n", e.b, e.q0);*/ + /* fprint(2, "'%s' deleted in tag at %d\n", e.b, e.q0);*/ break; case 'D': - /* threadprint(2, "'%s' deleted in body at %d\n", e.b, e.q0);*/ + /* fprint(2, "'%s' deleted in body at %d\n", e.b, e.q0);*/ break; case 'x': case 'X': /* Execute command. */ --- /acme/bin/source/adict/win.c Fri Dec 30 08:14:36 2005 +++ /acme/bin/source/adict/win.c Fri Dec 30 08:13:47 2005 @@ -9,7 +9,7 @@ { p = realloc(p, n); if(p == nil) - threadprint(2, "realloc failed: %r"); + fprint(2, "realloc failed: %r"); return p; } @@ -20,7 +20,7 @@ w->ctl = open("/mnt/acme/new/ctl", ORDWR); if(w->ctl<0 || read(w->ctl, buf, 12)!=12) - threadprint (2, "can't open window ctl file: %r"); + fprint (2, "can't open window ctl file: %r"); ctlwrite(w, "noscroll\n"); w->winid = atoi(buf); w->event = openfile(w, "event"); @@ -38,7 +38,7 @@ sprint(buf, "/mnt/acme/%d/%s", w->winid, f); fd = open(buf, ORDWR|OCEXEC); if(fd < 0) - threadprint (2,"can't open window %s file: %r", f); + fprint (2,"can't open window %s file: %r", f); return fd; } @@ -50,7 +50,7 @@ sprint(buf, "/mnt/acme/%d/body", w->winid); w->body = Bopen(buf, mode|OCEXEC); if(w->body == nil) - threadprint(2,"can't open window body file: %r"); + fprint(2,"can't open window body file: %r"); } void @@ -59,7 +59,7 @@ if(w->body == nil) openbody(w, OWRITE); if(Bwrite(w->body, s, n) != n) - threadprint(2,"write error to window: %r"); + fprint(2,"write error to window: %r"); Bflush(w->body); } @@ -71,11 +71,11 @@ if(w->data < 0) w->data = openfile(w, "data"); if(write(w->addr, addr, strlen(addr)) < 0){ - threadprint(2, "mail: warning: badd address %s:%r\n", addr); + fprint(2, "mail: warning: badd address %s:%r\n", addr); return; } if(write(w->data, repl, nrepl) != nrepl) - threadprint(2, "writing data: %r"); + fprint(2, "writing data: %r"); } static int @@ -104,10 +104,10 @@ while(m < q1){ n = sprint(buf, "#%d", m); if(write(w->addr, buf, n) != n) - threadprint(2,"writing addr: %r"); + fprint(2,"writing addr: %r"); n = read(w->data, buf, sizeof buf); if(n <= 0) - threadprint(2,"reading data: %r"); + fprint(2,"reading data: %r"); nr = nrunes(buf, n); while(m+nr >q1){ do; while(n>0 && (buf[--n]&0xC0)==0x80); @@ -128,7 +128,7 @@ if(w->addr < 0) w->addr = openfile(w, "addr"); if(write(w->addr, addr, strlen(addr)) < 0) - threadprint(2,"writing addr"); + fprint(2,"writing addr"); ctlwrite(w, "dot=addr\n"); } @@ -139,7 +139,7 @@ fd = openfile(w, "tag"); if(write(fd, s, n) != n) - threadprint(2,"tag write: %r"); + fprint(2,"tag write: %r"); close(fd); } @@ -150,7 +150,7 @@ n = strlen(s); if(write(w->ctl, s, n) != n) - threadprint(2,"write error to ctl file: %r"); + fprint(2,"write error to ctl file: %r"); } int @@ -206,7 +206,7 @@ if(w->nbuf == 0){ w->nbuf = read(w->event, w->buf, sizeof w->buf); if(w->nbuf <= 0) - threadprint(2,"event read error: %r"); + fprint(2,"event read error: %r"); w->bufp = w->buf; } w->nbuf--; @@ -222,7 +222,7 @@ while('0'<=(c=getec(w)) && c<='9') n = n*10+(c-'0'); if(c != ' ') - threadprint(2, "event number syntax"); + fprint(2, "event number syntax"); return n; } @@ -258,7 +258,7 @@ e->flag = geten(w); e->nr = geten(w); if(e->nr > EVENTSIZE) - threadprint(2, "wevent: event string too long"); + fprint(2, "wevent: event string too long"); e->nb = 0; for(i=0; inr; i++){ e->r[i] = geter(w, e->b+e->nb, &nb); @@ -267,7 +267,7 @@ e->r[e->nr] = 0; e->b[e->nb] = 0; if(getec(w) != '\n') - threadprint(2, "wevent: event syntax 2"); + fprint(2, "wevent: event syntax 2"); } void @@ -282,7 +282,7 @@ void wwriteevent(Win *w, Event *e) { - threadprint(w->event, "%c%c%d %d\n", e->c1, e->c2, e->q0, e->q1); + fprint(w->event, "%c%c%d %d\n", e->c1, e->c2, e->q0, e->q1); } int