tuse threaddaemonize - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7ffc5208a82cd7339c125956a9702ac08c0ff2f4
 (DIR) parent 96d6b19dcd4f359c3fa8eefcb8615082c840e184
 (HTM) Author: rsc <devnull@localhost>
       Date:   Tue, 28 Dec 2004 01:37:18 +0000
       
       use threaddaemonize
       
       Diffstat:
         M src/cmd/9pserve.c                   |      22 ++++++++--------------
         M src/cmd/plumb/plumber.c             |      13 +------------
       
       2 files changed, 9 insertions(+), 26 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/9pserve.c b/src/cmd/9pserve.c
       t@@ -149,19 +149,8 @@ threadmain(int argc, char **argv)
                if((afd = announce(addr, adir)) < 0)
                        sysfatal("announce %s: %r", addr);
        
       -        if(verbose) fprint(2, "9pserve forking\n");
       -        switch(fork()){
       -        case -1:
       -                sysfatal("fork: %r");
       -        case 0:
       -                if(verbose) fprint(2, "running mainproc\n");
       -                mainproc(nil);
       -                if(verbose) fprint(2, "mainproc finished\n");
       -                _exits(0);
       -        default:
       -                if(verbose) fprint(2, "9pserve exiting\n");
       -                _exits(0);
       -        }
       +        threaddaemonize();
       +        mainproc(nil);
        }
        
        void
       t@@ -220,6 +209,7 @@ listenthread(void *arg)
        
                io = ioproc();
                USED(arg);
       +        threadsetname("listen %s", adir);
                for(;;){
                        c = emalloc(sizeof(Conn));
                        c->fd = iolisten(io, adir, c->dir);
       t@@ -284,6 +274,7 @@ connthread(void *arg)
                Ioproc *io;
        
                c = arg;
       +        threadsetname("conn %s", c->dir);
                io = ioproc();
                fd = ioaccept(io, c->fd, c->dir);
                if(fd < 0){
       t@@ -491,7 +482,7 @@ openfdthread(void *v)
                c = v;
                fid = c->fdfid;
                io = ioproc();
       -
       +        threadsetname("openfd %s", c->fdfid);
                tot = 0;
                m = nil;
                if(c->fdmode == OREAD){
       t@@ -655,6 +646,7 @@ connoutthread(void *arg)
                c = arg;
                outq = c->outq;
                io = ioproc();
       +        threadsetname("connout %s", c->dir);
                while((m = recvq(outq)) != nil){
                        err = m->tx.type+1 != m->rx.type;
                        if(!err && m->isopenfd)
       t@@ -714,6 +706,7 @@ outputthread(void *arg)
        
                USED(arg);
                io = ioproc();
       +        threadsetname("output");
                while((m = recvq(outq)) != nil){
                        if(verbose > 1) fprint(2, "* <- %F\n", &m->tx);
                        rewritehdr(&m->tx, m->tpkt);
       t@@ -734,6 +727,7 @@ inputthread(void *arg)
                Msg *m;
                Ioproc *io;
        
       +        threadsetname("input");
                if(verbose) fprint(2, "input thread\n");
                io = ioproc();
                USED(arg);
 (DIR) diff --git a/src/cmd/plumb/plumber.c b/src/cmd/plumb/plumber.c
       t@@ -69,19 +69,8 @@ threadmain(int argc, char *argv[])
                rules = readrules(plumbfile, fd);
                close(fd);
        
       -        /*
       -         * Start all processes and threads from other proc
       -         * so we (main pid) can return to user.
       -         */
                if(dofork)
       -        switch(fork()){
       -        case -1:
       -                sysfatal("fork: %r");
       -        case 0:
       -                break;
       -        default:
       -                _exit(0);
       -        }
       +                threaddaemonize();
        
                printerrors = 0;
                makeports(rules);