URI: 
       trestore current directory after threadexec. this is dodgy. - 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 bf27f5872198e789df90c04b7cdac6bf73a612d9
   DIR parent 50e1783a7ed84bf5a8ede25a2fe52920882cef3b
  HTML Author: rsc <devnull@localhost>
       Date:   Sat, 15 May 2004 23:13:42 +0000
       
       restore current directory after threadexec.
       tthis is dodgy.
       
       Diffstat:
         M src/cmd/acme/exec.c                 |      55 +++++++++++++++++++++++++++----
       
       1 file changed, 48 insertions(+), 7 deletions(-)
       ---
   DIR diff --git a/src/cmd/acme/exec.c b/src/cmd/acme/exec.c
       t@@ -1280,7 +1280,10 @@ runproc(void *argvp)
                int sfd[3];
                int pipechar;
                char buf[512];
       +        int olddir;
       +        int ret;
                //static void *parg[2];
       +        char *rcarg[4];
                void **argv;
                Fsys *fs;
        
       t@@ -1317,11 +1320,6 @@ runproc(void *argvp)
                        pipechar = *t++;
                c->iseditcmd = iseditcmd;
                c->text = s;
       -        if(rdir != nil){
       -                dir = runetobyte(rdir, ndir);
       -                chdir(dir);        /* ignore error: probably app. window */
       -                free(dir);
       -        }
                if(newns){
                        nincl = 0;
                        incl = nil;
       t@@ -1431,7 +1429,30 @@ runproc(void *argvp)
                av[ac++] = arg;
                av[ac] = nil;
                c->av = av;
       -        threadexec(cpid, sfd, av[0], av);
       +
       +        /*
       +         * clumsy -- we're not running in a separate thread
       +         * so we have to save the current directory and put
       +         * it back when we're done.  if this gets to be a regular
       +         * thing we could change threadexec to take a directory too.
       +         */
       +        olddir = -1;
       +        if(rdir != nil){
       +                olddir = open(".", OREAD);
       +                dir = runetobyte(rdir, ndir);
       +                chdir(dir);        /* ignore error: probably app. window */
       +                free(dir);
       +        }
       +        ret = threadspawn(sfd, av[0], av);
       +        if(olddir >= 0){
       +                fchdir(olddir);
       +                close(olddir);
       +        }
       +        if(ret >= 0){
       +                if(cpid)
       +                        sendul(cpid, ret);
       +                threadexits("");
       +        }
        /* libthread uses execvp so no need to do this */
        #if 0
                e = av[0];
       t@@ -1474,7 +1495,27 @@ Hard:
                                c->text = news;
                        }
                }
       -        threadexecl(cpid, sfd, "rc", "rc", "-c", t, nil);
       +        olddir = -1;
       +        if(rdir != nil){
       +                olddir = open(".", OREAD);
       +                dir = runetobyte(rdir, ndir);
       +                chdir(dir);        /* ignore error: probably app. window */
       +                free(dir);
       +        }
       +        rcarg[0] = "rc";
       +        rcarg[1] = "-c";
       +        rcarg[2] = t;
       +        rcarg[3] = nil;
       +        ret = threadspawn(sfd, rcarg[0], rcarg);
       +        if(olddir >= 0){
       +                fchdir(olddir);
       +                close(olddir);
       +        }
       +        if(ret >= 0){
       +                if(cpid)
       +                        sendul(cpid, ret);
       +                threadexits("");
       +        }
                warning(nil, "exec rc: %r\n");
        
           Fail: