aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-05-15 23:13:42 +0000
committerrsc <devnull@localhost>2004-05-15 23:13:42 +0000
commitbf27f5872198e789df90c04b7cdac6bf73a612d9 (patch)
tree5d9f60c8f29ba3b1436ff0cac21d4a8e7c4b2025 /src
parent50e1783a7ed84bf5a8ede25a2fe52920882cef3b (diff)
downloadplan9port-bf27f5872198e789df90c04b7cdac6bf73a612d9.tar.gz
plan9port-bf27f5872198e789df90c04b7cdac6bf73a612d9.tar.bz2
plan9port-bf27f5872198e789df90c04b7cdac6bf73a612d9.zip
restore current directory after threadexec.
this is dodgy.
Diffstat (limited to 'src')
-rw-r--r--src/cmd/acme/exec.c55
1 files changed, 48 insertions, 7 deletions
diff --git a/src/cmd/acme/exec.c b/src/cmd/acme/exec.c
index 3bc10371..882f7c31 100644
--- a/src/cmd/acme/exec.c
+++ b/src/cmd/acme/exec.c
@@ -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;
@@ -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;
@@ -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];
@@ -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: