tLittle fixes. - 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 b1455f33a8a7b6826fcb0d4b3f4849e322755d28
 (DIR) parent be36ff68854c86247fdc769c0eaa89eb284b5ca7
 (HTM) Author: rsc <devnull@localhost>
       Date:   Fri, 30 Apr 2004 02:16:28 +0000
       
       Little fixes.
       
       Diffstat:
         M src/cmd/9term/win.c                 |      18 ++++++++++++------
         M src/cmd/bzip2/bzip2.c               |       3 +++
         M src/cmd/draw/gview.c                |       4 ++--
         M src/cmd/gzip/gzip.c                 |       3 +++
         M src/cmd/rc/exec.h                   |       1 +
         M src/lib9/_p9proc.c                  |      10 +++++++---
         M src/lib9/ffork-FreeBSD.c            |       7 ++++++-
         M src/lib9/ffork-Linux.c              |      33 ++++++++++++++++++++++++++++---
         M src/lib9/ffork-pthread.c            |       3 +++
         M src/lib9/main.c                     |       1 +
       
       10 files changed, 68 insertions(+), 15 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/9term/win.c b/src/cmd/9term/win.c
       t@@ -121,18 +121,24 @@ threadmain(int argc, char **argv)
                case 'd':
                        debug = 1;
                        break;
       +        case 'n':
       +                name = EARGF(usage());
       +                break;
                default:
                        usage();
                }ARGEND
        
                prog = argv;
        
       -        if(argc > 0){
       -                name = argv[0];
       -                argc--;
       -                argv++;
       -        }else
       -                name = "gnot";
       +        if(name == nil){
       +                if(argc > 0)
       +                        name = argv[0];
       +                else{
       +                        name = sysname();
       +                        if(name == nil)
       +                                name = "gnot";
       +                }
       +        }
        
                threadnotify(nopipes, 1);
                if((fs = nsmount("acme", "")) == 0)
 (DIR) diff --git a/src/cmd/bzip2/bzip2.c b/src/cmd/bzip2/bzip2.c
       t@@ -38,6 +38,9 @@ main(int argc, char **argv)
                case 'c':
                        stdout++;
                        break;
       +        case 'f':
       +                /* force */
       +                break;
                case 'd':
                        /*
                         * gnu tar expects bzip2 -d to decompress
 (DIR) diff --git a/src/cmd/draw/gview.c b/src/cmd/draw/gview.c
       t@@ -1934,9 +1934,9 @@ void doevent(void)
                                if (mobile) {
                                        mvtime = ev.mouse.msec + Mv_delay;
                                        prepare_mv(cur_sel.fp);
       +                                if (!lift_button(1, &ev.mouse, mvtime))
       +                                        save_mv(do_move(1, &ev.mouse));
                                }
       -                        if (!lift_button(1, &ev.mouse, mvtime) && mobile)
       -                                save_mv(do_move(1, &ev.mouse));
                        } else if (ev.mouse.buttons & But2)
                                do_emenu(2, &ev.mouse);
                        else if (ev.mouse.buttons & But3)
 (DIR) diff --git a/src/cmd/gzip/gzip.c b/src/cmd/gzip/gzip.c
       t@@ -52,6 +52,9 @@ main(int argc, char *argv[])
                        exec("gunzip", oargv);
                        sysfatal("exec gunzip failed");
                        break;
       +        case 'f':
       +                /* force */
       +                break;
                case 'v':
                        verbose++;
                        break;
 (DIR) diff --git a/src/cmd/rc/exec.h b/src/cmd/rc/exec.h
       t@@ -51,6 +51,7 @@ struct thread{
                int iflag;                        /* interactive? */
                int lineno;                        /* linenumber */
                int pid;                        /* process for Xpipewait to wait for */
       +        int done;                        /* have we seen a wait message for this process? */
                char status[NSTATUS];                /* status for Xpipewait */
                tree *treenodes;                /* tree nodes created by this process */
                thread *ret;                /* who continues when this finishes */
 (DIR) diff --git a/src/lib9/_p9proc.c b/src/lib9/_p9proc.c
       t@@ -45,14 +45,17 @@ _p9uproc(int inhandler)
                                h = 0;
                }
        
       -        if(inhandler)
       -                sysfatal("did not find uproc in signal handler");
       +        if(inhandler){
       +                fprint(2, "%s: did not find uproc for pid %d in signal handler\n", argv0, pid);
       +                abort();        
       +        }
        
                /* need to allocate */
                while((up = mallocz(sizeof(Uproc), 1)) == nil)
                        sleep(1000);
        
       -        up = mallocz(sizeof(Uproc), 1);
       +fprint(2, "alloc uproc for pid %d\n", pid);
       +        up->pid = pid;
                lock(&uproclock);
                h = pid%PIDHASH;
                for(i=0; i<PIDHASH; i++){
       t@@ -79,6 +82,7 @@ _p9uprocdie(void)
                int pid, i, h;
        
                pid = getpid();
       +fprint(2, "reap uproc for pid %d\n", pid);
                h = pid%PIDHASH;
                for(i=0; i<PIDHASH; i++){
                        up = alluproc[h];
 (DIR) diff --git a/src/lib9/ffork-FreeBSD.c b/src/lib9/ffork-FreeBSD.c
       t@@ -4,14 +4,19 @@ extern int __isthreaded;
        int
        ffork(int flags, void(*fn)(void*), void *arg)
        {
       +        int pid;
                void *p;
        
       +        _p9uproc(0);
                __isthreaded = 1;
                p = malloc(16384);
                if(p == nil)
                        return -1;
                memset(p, 0xFE, 16384);
       -        return rfork_thread(RFPROC|flags, (char*)p+16000, (int(*)(void*))fn, arg);
       +        pid = rfork_thread(RFPROC|flags, (char*)p+16000, (int(*)(void*))fn, arg);
       +        if(pid == 0)
       +                _p9uproc(0);
       +        return pid;
        }
        
        /*
 (DIR) diff --git a/src/lib9/ffork-Linux.c b/src/lib9/ffork-Linux.c
       t@@ -1,18 +1,41 @@
       +#include <u.h>
        #include <sched.h>
        #include <signal.h>
       -#include <lib9.h>
       +#include <libc.h>
       +#include "9proc.h"
        
        int fforkstacksize = 16384;
        
       +static int
       +tramp(void *v)
       +{
       +        void (*fn)(void*), *arg;
       +        void **v2;
       +
       +        _p9uproc(0);
       +        v2 = v;
       +        fn = v2[0];
       +        arg = v2[1];
       +        free(v2);
       +        fn(arg);
       +        return 0;
       +}
       +        
        int
        ffork(int flags, void (*fn)(void*), void *arg)
        {
       +        void **v;
                char *p;
                int cloneflag, pid;
        
       +        _p9uproc(0);
                p = malloc(fforkstacksize);
       -        if(p == nil)
       +        v = malloc(sizeof(void*)*2);
       +        if(p==nil || v==nil){
       +                free(p);
       +                free(v);
                        return -1;
       +        }
                cloneflag = 0;
                flags &= ~RFPROC;
                if(flags&RFMEM){
       t@@ -29,9 +52,13 @@ ffork(int flags, void (*fn)(void*), void *arg)
                        flags &= ~RFNOWAIT;
                if(flags){
                        fprint(2, "unknown rfork flags %x\n", flags);
       +                free(p);
       +                free(v);
                        return -1;
                }
       -        pid = clone((int(*)(void*))fn, p+fforkstacksize-16, cloneflag, arg);
       +        v[0] = fn;
       +        v[1] = arg;
       +        pid = clone(tramp, p+fforkstacksize-16, cloneflag, v);
                if(pid < 0)
                        free(p);
                return pid;
 (DIR) diff --git a/src/lib9/ffork-pthread.c b/src/lib9/ffork-pthread.c
       t@@ -14,8 +14,11 @@ ffork(int flags, void(*fn)(void*), void *arg)
                        return -1;
                }
        
       +        _p9uproc(0);
                if(pthread_create(&tid, NULL, (void*(*)(void*))fn, arg) < 0)
                        return -1;
       +        if((int)tid == 0)
       +                _p9uproc(0);
                return (int)tid;
        }
        
 (DIR) diff --git a/src/lib9/main.c b/src/lib9/main.c
       t@@ -7,6 +7,7 @@ extern void p9main(int, char**);
        int
        main(int argc, char **argv)
        {
       +        _p9uproc(0);
                p9main(argc, argv);
                exits("main");
                return 99;