diff options
author | Russ Cox <rsc@swtch.com> | 2012-10-22 12:32:09 -0400 |
---|---|---|
committer | Russ Cox <rsc@swtch.com> | 2012-10-22 12:32:09 -0400 |
commit | 9e4b56e7645e08311590355824863ecf9f334f0c (patch) | |
tree | e075835acb77327b3f6bedacb9d265a443065714 /src | |
parent | 81c2c5e775d83896f25981cf4c4e486c5cc91180 (diff) | |
download | plan9port-9e4b56e7645e08311590355824863ecf9f334f0c.tar.gz plan9port-9e4b56e7645e08311590355824863ecf9f334f0c.tar.bz2 plan9port-9e4b56e7645e08311590355824863ecf9f334f0c.zip |
libthread: add threadspawnd
R=rsc
http://codereview.appspot.com/6742064
Diffstat (limited to 'src')
-rw-r--r-- | src/libthread/exec.c | 17 | ||||
-rw-r--r-- | src/libthread/threadimpl.h | 5 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/libthread/exec.c b/src/libthread/exec.c index 1875eb98..62805ba2 100644 --- a/src/libthread/exec.c +++ b/src/libthread/exec.c @@ -12,7 +12,7 @@ execproc(void *v) Waitmsg *w; e = v; - pid = _threadspawn(e->fd, e->cmd, e->argv); + pid = _threadspawn(e->fd, e->cmd, e->argv, e->dir); sendul(e->c, pid); if(pid > 0){ w = waitfor(pid); @@ -25,7 +25,7 @@ execproc(void *v) } int -_runthreadspawn(int *fd, char *cmd, char **argv) +_runthreadspawn(int *fd, char *cmd, char **argv, char *dir) { int pid; Execjob e; @@ -33,6 +33,7 @@ _runthreadspawn(int *fd, char *cmd, char **argv) e.fd = fd; e.cmd = cmd; e.argv = argv; + e.dir = dir; e.c = chancreate(sizeof(void*), 0); proccreate(execproc, &e, 65536); pid = recvul(e.c); @@ -57,7 +58,7 @@ threadwaitchan(void) } int -_threadspawn(int fd[3], char *cmd, char *argv[]) +_threadspawn(int fd[3], char *cmd, char *argv[], char *dir) { int i, n, p[2], pid; char exitstr[100]; @@ -77,6 +78,8 @@ _threadspawn(int fd[3], char *cmd, char *argv[]) return -1; case 0: /* can't RFNOTEG - will lose tty */ + if(dir != nil ) + chdir(dir); /* best effort */ dup2(fd[0], 0); dup2(fd[1], 1); dup2(fd[2], 2); @@ -112,7 +115,13 @@ _threadspawn(int fd[3], char *cmd, char *argv[]) int threadspawn(int fd[3], char *cmd, char *argv[]) { - return _runthreadspawn(fd, cmd, argv); + return _runthreadspawn(fd, cmd, argv, nil); +} + +int +threadspawnd(int fd[3], char *cmd, char *argv[], char *dir) +{ + return _runthreadspawn(fd, cmd, argv, dir); } int diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h index 9518f785..144a2136 100644 --- a/src/libthread/threadimpl.h +++ b/src/libthread/threadimpl.h @@ -121,6 +121,7 @@ struct Execjob int *fd; char *cmd; char **argv; + char *dir; Channel *c; }; @@ -203,8 +204,8 @@ extern void _threadsetproc(Proc*); extern int _threadlock(Lock*, int, ulong); extern void _threadunlock(Lock*, ulong); extern void _pthreadinit(void); -extern int _threadspawn(int*, char*, char**); -extern int _runthreadspawn(int*, char*, char**); +extern int _threadspawn(int*, char*, char**, char*); +extern int _runthreadspawn(int*, char*, char**, char*); extern void _threadsetupdaemonize(void); extern void _threaddodaemonize(char*); extern void _threadpexit(void); |