URI: 
       tmake work with new thread library - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 60535a5ff621d2e0f1eb91a08c0e624cc6c76fbd
   DIR parent f99790979b4a659d7f6e490fbb8b26d630804eed
  HTML Author: rsc <devnull@localhost>
       Date:   Sun, 26 Dec 2004 21:37:31 +0000
       
       make work with new thread library
       
       Diffstat:
         M src/cmd/9term/9term.c               |      16 ++++++++--------
         M src/cmd/9term/rcstart.c             |      24 +++++++++++++++++-------
         M src/cmd/9term/win.c                 |      24 ++++++++++++++++++++----
       
       3 files changed, 45 insertions(+), 19 deletions(-)
       ---
   DIR diff --git a/src/cmd/9term/9term.c b/src/cmd/9term/9term.c
       t@@ -20,7 +20,7 @@ enum
        int noecho = 0;
        
        void servedevtext(void);
       -void listenthread(void*);
       +void listenproc(void*);
        void textthread(void*);
        
        typedef struct Text        Text;
       t@@ -249,7 +249,7 @@ threadmain(int argc, char *argv[])
        
                initdraw(0, nil, "9term");
                notify(hangupnote);
       -        notifyatsig(SIGCHLD, 1);
       +        noteenable("sys: child");
                servedevtext();
        
                mc = initmouse(nil, screen);
       t@@ -322,7 +322,7 @@ hostproc(void *arg)
                        yield();
        
                        i = 1-i;        /* toggle */
       -                n = threadread(rcfd, rcbuf[i].data, sizeof rcbuf[i].data);
       +                n = read(rcfd, rcbuf[i].data, sizeof rcbuf[i].data);
                        if(n <= 0){
                                if(n < 0)
                                        fprint(2, "9term: host read error: %r\n");
       t@@ -338,7 +338,7 @@ void
        hoststart(void)
        {
                hostc = chancreate(sizeof(int), 0);
       -        threadcreate(hostproc, hostc, 32*1024);
       +        proccreate(hostproc, hostc, 32*1024);
        }
        
        void
       t@@ -1868,25 +1868,25 @@ servedevtext(void)
                }
        
                putenv("text9term", buf);
       -        threadcreate(listenthread, nil, STACK);
       +        proccreate(listenproc, nil, STACK);
                strcpy(thesocket, buf+5);
                atexit(removethesocket);
        }
        
        void
       -listenthread(void *arg)
       +listenproc(void *arg)
        {
                int fd;
                char dir[100];
        
                USED(arg);
                for(;;){
       -                fd = threadlisten(adir, dir);
       +                fd = listen(adir, dir);
                        if(fd < 0){
                                close(afd);
                                return;
                        }
       -                threadcreate(textthread, (void*)fd, STACK);
       +                proccreate(textthread, (void*)fd, STACK);
                }
        }
        
   DIR diff --git a/src/cmd/9term/rcstart.c b/src/cmd/9term/rcstart.c
       t@@ -4,19 +4,24 @@
        #include "term.h"
        
        static void
       -sys(char *buf)
       +sys(char *buf, int devnull)
        {
                char buf2[100];
                char *f[20];
                int nf, pid;
        
       +        notedisable("sys: child");
                strcpy(buf2, buf);
                nf = tokenize(buf2, f, nelem(f));
                f[nf] = nil;
                switch(pid = fork()){
                case 0:
       +                close(1);
       +                open("/dev/null", OREAD);
       +                close(2);
       +                open("/dev/null", OREAD);
                        execvp(f[0], f);
       -                _exits("oops");
       +                _exit(2);
                default:
                        waitpid();
                }
       t@@ -43,18 +48,23 @@ rcstart(int argc, char **argv, int *pfd, int *tfd)
                 * fd0 is slave (tty), fd1 is master (pty)
                 */
                fd[0] = fd[1] = -1;
       -        if(getpts(fd, slave) < 0)
       +        if(getpts(fd, slave) < 0){
       +                exit(3);
                        sysfatal("getpts: %r\n");
       -        switch(pid = fork()) {
       +        }
       +        notedisable("sys: window size change");
       +        pid = fork();
       +        switch(pid){
                case 0:
                        putenv("TERM", "9term");
                        sfd = childpty(fd, slave);
                        dup(sfd, 0);
                        dup(sfd, 1);
                        dup(sfd, 2);
       -                sys("stty tabs -onlcr onocr icanon echo erase '^h' intr '^?'");
       +                sys("stty tabs -onlcr icanon echo erase '^h' intr '^?'", 0);
       +                sys("stty onocr", 1);        /* not available on mac */
                        if(noecho)
       -                        sys("stty -echo");
       +                        sys("stty -echo", 0);
                        for(i=3; i<100; i++)
                                close(i);
                        signal(SIGINT, SIG_DFL);
       t@@ -62,7 +72,7 @@ rcstart(int argc, char **argv, int *pfd, int *tfd)
                        signal(SIGTERM, SIG_DFL);
                        execvp(argv[0], argv);
                        fprint(2, "exec %s failed: %r\n", argv[0]);
       -                _exits("oops");
       +                _exit(2);
                        break;
                case -1:
                        sysfatal("proc failed: %r");
   DIR diff --git a/src/cmd/9term/win.c b/src/cmd/9term/win.c
       t@@ -110,6 +110,20 @@ waitthread(void *v)
        }
        
        void
       +hangupnote(void *a, char *msg)
       +{
       +        if(strcmp(msg, "hangup") == 0 && pid != 0){
       +                postnote(PNGROUP, pid, "hangup");
       +                noted(NDFLT);
       +        }
       +        if(strstr(msg, "child")){
       +                /* bug: do better */
       +                threadexitsall(0);
       +        }
       +        noted(NDFLT);
       +}
       +
       +void
        threadmain(int argc, char **argv)
        {
                int fd, id;
       t@@ -140,7 +154,10 @@ threadmain(int argc, char **argv)
                        }
                }
        
       -        threadnotify(nopipes, 1);
       +        notedisable("sys: write on closed pipe");
       +        noteenable("sys: child");
       +        notify(hangupnote);
       +
                if((fs = nsmount("acme", "")) == 0)
                        sysfatal("nsmount acme: %r");
                ctlfd = fsopen(fs, "new/ctl", ORDWR|OCEXEC);
       t@@ -184,7 +201,7 @@ threadmain(int argc, char **argv)
                fswrite(ctlfd, buf, strlen(buf));
                
                updatewinsize(25, 80, 0, 0);
       -        threadcreate(stdoutproc, nil, STACK);
       +        proccreate(stdoutproc, nil, STACK);
                stdinproc(nil);
        }
        
       t@@ -420,13 +437,12 @@ stdoutproc(void *v)
                char x[16], hold[UTFmax];
        
                USED(v);
       -        threadnotify(nopipes, 1);
                buf = malloc(8192+UTFmax+1);
                npart = 0;
                for(;;){
                        /* Let typing have a go -- maybe there's a rubout waiting. */
                        yield();
       -                n = threadread(fd1, buf+npart, 8192);
       +                n = read(fd1, buf+npart, 8192);
                        if(n < 0)
                                error(nil);
                        if(n == 0)