commit 9ca6e21f3d0ea9b9bab8b4661d03d30ed61fd79d
parent 9e4b56e7645e08311590355824863ecf9f334f0c
Author: Russ Cox <rsc@swtch.com>
Date: Mon, 22 Oct 2012 12:32:31 -0400
acme: use threadspawnd to avoid changing "." of current process
R=rsc
http://codereview.appspot.com/6736060
Diffstat:
1 file changed, 8 insertions(+), 29 deletions(-)
diff --git a/src/cmd/acme/exec.c b/src/cmd/acme/exec.c
@@ -1352,7 +1352,6 @@ runproc(void *argvp)
int sfd[3];
int pipechar;
char buf[512];
- int olddir;
int ret;
/*static void *parg[2]; */
char *rcarg[4];
@@ -1507,24 +1506,11 @@ runproc(void *argvp)
av[ac] = nil;
c->av = 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 = nil;
+ if(rdir != nil)
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);
- }
+ ret = threadspawnd(sfd, av[0], av, dir);
+ free(dir);
if(ret >= 0){
if(cpid)
sendul(cpid, ret);
@@ -1572,13 +1558,9 @@ Hard:
c->text = news;
}
}
- olddir = -1;
- if(rdir != nil){
- olddir = open(".", OREAD);
+ dir = nil;
+ if(rdir != nil)
dir = runetobyte(rdir, ndir);
- chdir(dir); /* ignore error: probably app. window */
- free(dir);
- }
shell = acmeshell;
if(shell == nil)
shell = "rc";
@@ -1586,11 +1568,8 @@ Hard:
rcarg[1] = "-c";
rcarg[2] = t;
rcarg[3] = nil;
- ret = threadspawn(sfd, rcarg[0], rcarg);
- if(olddir >= 0){
- fchdir(olddir);
- close(olddir);
- }
+ ret = threadspawnd(sfd, rcarg[0], rcarg, dir);
+ free(dir);
if(ret >= 0){
if(cpid)
sendul(cpid, ret);