commit 605c0ea102e334b6c05d635ca0e5b93bad0031ec from: rsc date: Wed Feb 08 22:39:54 2006 UTC cleanup commit - 5a1e9de7b160033e85a77ad4c60193186364a2fb commit + 605c0ea102e334b6c05d635ca0e5b93bad0031ec blob - 7974a8b3230c54704a9dbb0392d1eb115c23a03f blob + 0a4661c1f4e578b2c6a8e4cdaa59c70233f14774 --- src/cmd/faces/faces.h +++ src/cmd/faces/faces.h @@ -45,7 +45,7 @@ extern char date[]; extern char *maildir; extern char **maildirs; extern int nmaildirs; -extern CFsys *upasfs; +extern CFsys *mailfs; Face* nextface(void); void findbit(Face*); blob - 4be56230a4a4b8ad5f05c97186204b1fa2fd513e blob + 862188490c00e539bfed5363236d2e6f75979802 --- src/cmd/faces/main.c +++ src/cmd/faces/main.c @@ -3,7 +3,6 @@ #include #include #include -//jpc #include /* for support routines only */ #include #include #include @@ -20,6 +19,8 @@ enum Infolines = 9, HhmmTime = 18*60*60, /* max age of face to display hh:mm time */ + + STACK = 32768 }; enum @@ -27,6 +28,7 @@ enum Mainp, Timep, Mousep, + Resizep, NPROC }; @@ -34,7 +36,8 @@ int pids[NPROC]; char *procnames[] = { "main", "time", - "mouse" + "mouse", + "resize", }; Rectangle leftright = {0, 0, 20, 15}; @@ -57,7 +60,7 @@ uchar rightdata[] = { 0x18, 0x00, 0x00, 0x10, 0x00 }; -CFsys *upasfs; +CFsys *mailfs; Mousectl *mousectl; Image *blue; /* full arrow */ Image *bgrnd; /* pale blue background color */ @@ -74,7 +77,7 @@ int ndown; char date[64]; Face **faces; -char *maildir = "/mail/fs/mbox"; +char *maildir = "INBOX"; ulong now; Point datep = { 8, 6 }; @@ -83,6 +86,7 @@ Point enddate; /* where date ends on display; used t Rectangle leftr; /* location of left arrow on display */ Rectangle rightr; /* location of right arrow on display */ void updatetimes(void); +void eresized(int); void setdate(void) @@ -95,15 +99,12 @@ setdate(void) void init(void) { -#if 0 - mousefd = open("/dev/mouse", OREAD); - if(mousefd < 0){ - fprint(2, "faces: can't open mouse: %r\n"); - threadexitsall("mouse"); - } -#endif - upasfs = nsmount("upasfs",nil); - mousectl = initmouse(nil,screen); + mailfs = nsmount("mail", nil); + if(mailfs == nil) + sysfatal("mount mail: %r"); + mousectl = initmouse(nil, screen); + if(mousectl == nil) + sysfatal("initmouse: %r"); initplumb(); /* make background color */ @@ -332,7 +333,7 @@ addface(Face *f) /* always adds at 0 */ lockdisplay(display); if(first != 0){ first = 0; - resized(); + eresized(0); } findbit(f); @@ -366,48 +367,23 @@ addface(Face *f) /* always adds at 0 */ unlockdisplay(display); } -#if 0 void loadmboxfaces(char *maildir) { - int dirfd; - Dir *d; - int i, n; - - dirfd = open(maildir, OREAD); - if(dirfd >= 0){ - chdir(maildir); - while((n = dirread(dirfd, &d)) > 0){ - for(i=0; i 0){ - for(i=0; ibuttons = 0; - return 0; - } - //jpc n = eatomouse(m, buf, n); - if(n > 0) - return 1; - } + while(recv(mousectl->resizec, 0) == 1) + eresized(1); } -#endif + int getmouse(Mouse *m) { @@ -573,19 +534,13 @@ getmouse(Mouse *m) if(eof) return 0; - if( readmouse(mousectl) < 0 ) { + if(readmouse(mousectl) < 0){ eof = 1; m->buttons = 0; return 0; } - else { - *m = mousectl->m; -/* m->buttons = mousectl->m.buttons; - m->xy.x = mousectl->m.xy.x; - m->xy.y = mousectl->m.xy.y; - m->msec = mousectl->m.msec; */ - return 1; - } + *m = mousectl->m; + return 1; } enum @@ -680,9 +635,10 @@ click(int button, Mouse *m) } void -mouseproc(void *dummy) +mouseproc(void *v) { Mouse mouse; + USED(v); while(getmouse(&mouse)){ if(mouse.buttons == 1) @@ -700,36 +656,10 @@ mouseproc(void *dummy) void killall(char *s) { - int i, pid; - - pid = getpid(); - for(i=0; i= 0) - killall("process died"); - threadexitsall(nil); - } - if(index >= 0) - pids[index] = pid; -} - -void usage(void) { fprint(2, "usage: faces [-hi] [-m maildir] -W winsize\n"); @@ -741,6 +671,8 @@ threadmain(int argc, char *argv[]) { int i; + rfork(RFNOTEG); + ARGBEGIN{ case 'h': history++; @@ -772,8 +704,9 @@ threadmain(int argc, char *argv[]) eresized(0); pids[Mainp] = getpid(); - pids[Timep] = proccreate(timeproc, nil, 16000); - pids[Mousep] = proccreate(mouseproc, nil, 16000); + pids[Timep] = proccreate(timeproc, nil, STACK); + pids[Mousep] = proccreate(mouseproc, nil, STACK); + pids[Resizep] = proccreate(resizeproc, nil, STACK); if(initload) for(i = 0; i < nmaildirs; i++) loadmboxfaces(maildirs[i]); blob - a61e2d81c2cd75dd5ba1f11d797d8ae1b142b67d blob + 1807fd3878f89163797cb52babe0addd2c69c4be --- src/cmd/faces/plumb.c +++ src/cmd/faces/plumb.c @@ -1,17 +1,15 @@ #include #include +#include #include -#include #include #include #include <9pclient.h> +#include #include "faces.h" -static int showfd = -1; -static int seefd = -1; -static int logfd = -1; -static char *user; -static char *logtag; +static CFid* showfd; +static CFid* seefd; char **maildirs; int nmaildirs; @@ -19,20 +17,10 @@ int nmaildirs; void initplumb(void) { - showfd = plumbopen("send", OWRITE); - seefd = plumbopen("seemail", OREAD); - - if(seefd < 0){ - logfd = open(unsharp("#9/log/mail"), OREAD); - seek(logfd, 0LL, 2); - user = getenv("user"); - if(user == nil){ - fprint(2, "faces: can't find user name: %r\n"); - exits("$user"); - } - logtag = emalloc(32+strlen(user)+1); - sprint(logtag, " delivered %s From ", user); - } + showfd = plumbopenfid("send", OWRITE); + seefd = plumbopenfid("seemail", OREAD); + if(showfd == nil || seefd == nil) + sysfatal("plumbopen: %r"); } void @@ -75,7 +63,7 @@ showmail(Face *f) pm.attr = &a; pm.ndata = strlen(s); pm.data = s; - plumbsend(showfd,&pm); + plumbsendtofid(showfd, &pm); } char* @@ -114,43 +102,6 @@ setname(Face *f, char *sender) } } -int -getc(void) -{ - static uchar buf[512]; - static int nbuf = 0; - static int i = 0; - - while(i == nbuf){ - i = 0; - nbuf = read(logfd, buf, sizeof buf); - if(nbuf == 0){ - sleep(15000); - continue; - } - if(nbuf < 0) - return -1; - } - return buf[i++]; -} - -char* -getline(char *buf, int n) -{ - int i, c; - - for(i=0; i= 0){ - m = plumbrecv(seefd); - if(m == nil) - killall("error on seemail plumb port"); - t = value(m->attr, "mailtype", ""); - if(strcmp(t, "delete") == 0) - delete(m->data, value(m->attr, "digest", nil)); - else if(strcmp(t, "new") != 0) - fprint(2, "faces: unknown plumb message type %s\n", t); - else for(i=0; idata,"/mail/fs/",strlen("/mail/fs/")) == 0) - m->data += strlen("/mail/fs/"); - if(strncmp(m->data, maildirs[i], strlen(maildirs[i])) == 0) - goto Found; - } - plumbfree(m); - continue; + m = plumbrecvfid(seefd); + if(m == nil) + killall("error on seemail plumb port"); + t = value(m->attr, "mailtype", ""); + if(strcmp(t, "delete") == 0) + delete(m->data, value(m->attr, "digest", nil)); + else if(strcmp(t, "new") != 0) + fprint(2, "faces: unknown plumb message type %s\n", t); + else for(i=0; idata,"/mail/fs/",strlen("/mail/fs/")) == 0) + m->data += strlen("/mail/fs/"); + if(strncmp(m->data, maildirs[i], strlen(maildirs[i])) == 0) + goto Found; + } + plumbfree(m); + continue; - Found: - xtime = parsedate(value(m->attr, "date", date)); - digestp = value(m->attr, "digest", nil); - if(alreadyseen(digestp)){ - /* duplicate upas/fs can send duplicate messages */ - plumbfree(m); - continue; - } - senderp = estrdup(value(m->attr, "sender", "???")); - showmailp = estrdup(m->data); - if(digestp) - digestp = estrdup(digestp); + Found: + xtime = parsedate(value(m->attr, "date", date)); + digestp = value(m->attr, "digest", nil); + if(alreadyseen(digestp)){ + /* duplicate upas/fs can send duplicate messages */ plumbfree(m); - }else{ - if(logrecv(&senderp, &xtime) <= 0) - killall("error reading log file"); - showmailp = estrdup(""); - digestp = nil; + continue; } - setname(f, senderp); - f->time = xtime; - f->tm = *localtime(xtime); - f->str[Sshow] = showmailp; - f->str[Sdigest] = digestp; - return f; + senderp = estrdup(value(m->attr, "sender", "???")); + showmailp = estrdup(m->data); + if(digestp) + digestp = estrdup(digestp); + plumbfree(m); } return nil; } @@ -332,6 +234,8 @@ iline(char *data, char **pp) { char *p; + if(*data == 0) + return nil; for(p=data; *p!='\0' && *p!='\n'; p++) ; if(*p == '\n') @@ -344,28 +248,16 @@ Face* dirface(char *dir, char *num) { Face *f; - char *from, *date; - char buf[1024], *info, *p, *digest; + char buf[1024], *fld[3], *info, *p, *t, *s; int n; ulong len; CFid *fid; -#if 0 - /* - * loadmbox leaves us in maildir, so we needn't - * walk /mail/fs/mbox for each face; this makes startup - * a fair bit quicker. - */ - if(getwd(pwd, sizeof pwd) != nil && strcmp(pwd, dir) == 0) - sprint(buf, "%s/info", num); - else - sprint(buf, "%s/%s/info", dir, num); -#endif sprint(buf, "%s/%s/info", dir, num); - len = fsdirlen(upasfs, buf); + len = fsdirlen(mailfs, buf); if(len <= 0) return nil; - fid = fsopen(upasfs,buf, OREAD); + fid = fsopen(mailfs, buf, OREAD); if(fid == nil) return nil; info = emalloc(len+1); @@ -377,22 +269,22 @@ dirface(char *dir, char *num) } info[n] = '\0'; f = emalloc(sizeof(Face)); - from = iline(info, &p); /* from */ - iline(p, &p); /* to */ - iline(p, &p); /* cc */ - iline(p, &p); /* replyto */ - date = iline(p, &p); /* date */ - setname(f, estrdup(from)); - f->time = parsedate(date); - f->tm = *localtime(f->time); + for(p=info; (s=iline(p, &p)) != nil; ){ + t = strchr(s, ' '); + if(t == nil) + continue; + *t++ = 0; + if(strcmp(s, "unixdate") == 0){ + f->time = atoi(t); + f->tm = *localtime(f->time); + } + else if(strcmp(s, "from") == 0 && tokenize(t, fld, 3) >= 2) + setname(f, estrdup(fld[1])); + else if(strcmp(s, "digest") == 0) + f->str[Sdigest] = estrdup(t); + } sprint(buf, "%s/%s", dir, num); f->str[Sshow] = estrdup(buf); - iline(p, &p); /* subject */ - iline(p, &p); /* mime content type */ - iline(p, &p); /* mime disposition */ - iline(p, &p); /* filename */ - digest = iline(p, &p); /* digest */ - f->str[Sdigest] = estrdup(digest); free(info); return f; } blob - 7577acaeaf432ac9bece1835a3af24e6fed1edef blob + 6e8001ca87a78966043e03919f5f3725e78f51fe --- src/cmd/upas/common/aux.c +++ src/cmd/upas/common/aux.c @@ -30,8 +30,8 @@ append_match(Resub *subexp, String *sp, int se) { char *cp, *ep; - cp = subexp[se].s.sp; /* jpc .sp -> .s.sp */ - ep = subexp[se].e.ep; /* jpc .ep -> .e.ep */ + cp = subexp[se].s.sp; + ep = subexp[se].e.ep; for (; cp < ep; cp++) s_putc(sp, *cp); s_terminate(sp); @@ -53,7 +53,7 @@ shellchars(char *cp) return 0; } -static char *specialchars = " ()<>{};=\\'\`^&|"; +static char *specialchars = " ()<>{};=\\'`^&|"; static char *escape = "%%"; int blob - 4bbaff83384400e35fc2159a9961b25ef94348b3 blob + 21b34a12ebeef5ab2507e4e8e4bc8241d5430c8b --- src/cmd/upas/common/config.c +++ src/cmd/upas/common/config.c @@ -9,3 +9,19 @@ char *SHELL = "#9/bin/rc"; char *POST = "#9/sys/lib/post/dispatch"; int MBOXMODE = 0662; + +void +upasconfig(void) +{ + static int did; + + if(did) + return; + did = 1; + MAILROOT = unsharp(MAILROOT); + UPASLOG = unsharp(UPASLOG); + UPASLIB = unsharp(UPASLIB); + UPASBIN = unsharp(UPASBIN); + SHELL = unsharp(SHELL); + POST = unsharp(POST); +} blob - 7266859d12cd813b7597b64d66f15728e8a7eca9 blob + c767d7cec631a37ef452945f7fa98459d3f141bf Binary files src/cmd/upas/common/libcommon.a and src/cmd/upas/common/libcommon.a differ blob - 67f367981d81015260bf8a7bce01b9ff594d41b8 blob + a9d4f0f811341c6312607af5bf9465778440a267 --- src/cmd/upas/common/libsys.c +++ src/cmd/upas/common/libsys.c @@ -33,24 +33,7 @@ getlog(void) { return getuser(); } -#if 0 /* jpc */ -extern char * -getlog(void) -{ - static char user[64]; - int fd; - int n; - fd = open("/dev/user", 0); - if(fd < 0) - return nil; - if((n=read(fd, user, sizeof(user)-1)) <= 0) - return nil; - close(fd); - user[n] = 0; - return user; -} -#endif /* jpc */ /* * return the lock name (we use one lock per directory) */ @@ -702,66 +685,19 @@ void pipesigoff(void) { atnotify(catchpipe, 0); -} - -void -exit9(int i) -{ - char buf[32]; - - if(i == 0) - exits(0); - snprint(buf, sizeof(buf), "%d", i); - exits(buf); -} - -static int -islikeatty(int fd) -{ - Dir *d; - int rv; - - d = dirfstat(fd); - if(d == nil) - return 0; - rv = strcmp(d->name, "cons") == 0; - free(d); - return rv; -} - -#if 0 -/* jpc */ -static int -islikeatty(int fd) -{ - char buf[64]; - - if(fd2path(fd, buf, sizeof buf) != 0) - return 0; - - /* might be /mnt/term/dev/cons */ - return strlen(buf) >= 9 && strcmp(buf+strlen(buf)-9, "/dev/cons") == 0; } -#endif extern int holdon(void) { - int fd; - - if(!islikeatty(0)) - return -1; - - fd = open("/dev/consctl", OWRITE); - write(fd, "holdon", 6); - - return fd; + /* XXX talk to 9term? */ + return -1; } extern int sysopentty(void) { - return open("/dev/cons", ORDWR); + return open("/dev/tty", ORDWR); } extern void @@ -786,11 +722,13 @@ sysfiles(void) extern String * mboxpath(char *path, char *user, String *to, int dot) { + upasconfig(); + if (dot || *path=='/' || strncmp(path, "./", 2) == 0 || strncmp(path, "../", 3) == 0) { to = s_append(to, path); } else { - to = s_append(to, unsharp(MAILROOT)); + to = s_append(to, MAILROOT); to = s_append(to, "/box/"); to = s_append(to, user); to = s_append(to, "/"); @@ -885,35 +823,7 @@ username(String *from) char * remoteaddr(int fd, char *dir) { - char buf[128], *p; - int n; - - if(dir == 0){ - fprint(2,"remoteaddr: called fd2path: fixme\n"); /* jpc - if(fd2path(fd, buf, sizeof(buf)) != 0) - return ""; */ - - /* parse something of the form /net/tcp/nnnn/data */ - p = strrchr(buf, '/'); - if(p == 0) - return ""; - strncpy(p+1, "remote", sizeof(buf)-(p-buf)-2); - } else - snprint(buf, sizeof buf, "%s/remote", dir); - buf[sizeof(buf)-1] = 0; - - fd = open(buf, OREAD); - if(fd < 0) - return ""; - n = read(fd, buf, sizeof(buf)-1); - close(fd); - if(n > 0){ - buf[n] = 0; - p = strchr(buf, '!'); - if(p) - *p = 0; - return strdup(buf); - } + /* XXX should call netconninfo */ return ""; } blob - 8cfaf267e8c51405770c3eb38b1ff6acd6f2f856 blob + 5cd01233914eaddd6857e488d8597408b83b8fda --- src/cmd/upas/common/mkfile +++ src/cmd/upas/common/mkfile @@ -2,19 +2,17 @@ LIB=libcommon.a -OFILES=aux.$O\ - become.$O\ +OFILES=\ + appendfiletombox.$O\ + aux.$O\ + config.$O\ + libsys.$O\ mail.$O\ process.$O\ - libsys.$O\ - config.$O\ - appendfiletombox.$O\ -HFILES=common.h\ +HFILES=\ + common.h\ sys.h\ <$PLAN9/src/mklib -nuke:V: - mk clean - rm -f libcommon.a blob - 16b21aefe4ad3db08a1f982ed6183e9cb2b64ed0 blob + 56725a88715877d651cf97390c7002fc3be2d1e5 --- src/cmd/upas/common/process.c +++ src/cmd/upas/common/process.c @@ -93,10 +93,8 @@ noshell_proc_start(char **av, stream *inp, stream *out dup(pp->std[i]->fd, i); for (n = sysfiles(); i < n; i++) close(i); - if(who) { - fprint(2,"process.c: trying to become(%s,%s)\n",av,who); - // jpc become(av, who); - } + if(who) + fprint(2, "warning: cannot run %s as %s\n", av[0], who); exec(av[0], av); perror("proc_start"); exits("proc_start"); @@ -116,7 +114,8 @@ proc_start(char *cmd, stream *inp, stream *outp, strea { char *av[4]; - av[0] = unsharp(SHELL); + upasconfig(); + av[0] = SHELL; av[1] = "-c"; av[2] = cmd; av[3] = 0; blob - 960aebb37327c9dc5b510a4a6e78d021d32f01f4 blob + 506915584fbc74b783416704c77a7fe73fb4083e --- src/cmd/upas/common/sys.h +++ src/cmd/upas/common/sys.h @@ -6,7 +6,7 @@ #include #include #include -#include "libString.h" /* jpc String.h -> libString.h */ +#include /* * for the lock routines in libsys.c @@ -19,7 +19,7 @@ struct Mlock { }; /* - * from config.c + * from config.c - call upasconfig() before using */ extern char *MAILROOT; /* root of mail system */ extern char *UPASLOG; /* log directory */ @@ -29,6 +29,7 @@ extern char *UPASTMP; /* temporary directory */ extern char *SHELL; /* path name of shell */ extern char *POST; /* path name of post server addresses */ extern int MBOXMODE; /* default mailbox protection mode */ +extern void upasconfig(void); /* * files in libsys.c @@ -58,7 +59,6 @@ extern int syskill(int); extern int syskillpg(int); extern int syscreate(char*, int, ulong); extern Mlock *trylock(char *); -extern void exit9(int); extern void pipesig(int*); extern void pipesigoff(void); extern int holdon(void); blob - 4ea9adb32ebdda4a9e3c4abb9e0e082dec9b2bb7 blob + ebffcdd313d1fd681d603e9a01ee110961f54234 --- src/cmd/upas/fs/pop3.c +++ src/cmd/upas/fs/pop3.c @@ -231,10 +231,8 @@ pop3login(Pop *pop) if(pop->needtls && !pop->encrypted) return "could not negotiate TLS"; - up = auth_getuserpasswd(auth_getkey, "role=client proto=pass service=pop dom=%q%s", + up = auth_getuserpasswd(auth_getkey, "proto=pass role=client service=pop dom=%q%s", pop->host, ubuf); - /* up = auth_getuserpasswd(auth_getkey, "proto=pass service=pop dom=%q%s", - pop->host, ubuf); jpc */ if(up == nil) return "no usable keys found";