tacme: use threadspawnd to avoid changing "." of current process - 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 9ca6e21f3d0ea9b9bab8b4661d03d30ed61fd79d (DIR) parent 9e4b56e7645e08311590355824863ecf9f334f0c (HTM) 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: M src/cmd/acme/exec.c | 37 +++++++------------------------ 1 file changed, 8 insertions(+), 29 deletions(-) --- (DIR) diff --git a/src/cmd/acme/exec.c b/src/cmd/acme/exec.c t@@ -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]; t@@ -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); t@@ -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"; t@@ -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);