diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-02-07 18:55:02 -0800 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-02-07 19:57:03 -0800 |
| commit | 93450abb4bf6a755b343ca459bbeff92540a7822 (patch) | |
| tree | ee49c759c04ab7efb83025b9ed6b04878711ea39 /src/rt/rust_run_program.cpp | |
| parent | 5131216fa6826509bb31672e5fde15b18eeff5d7 (diff) | |
| download | rust-93450abb4bf6a755b343ca459bbeff92540a7822.tar.gz rust-93450abb4bf6a755b343ca459bbeff92540a7822.zip | |
Make process-spawning take environments and working directories, remove procsrv task from compiletest.
Diffstat (limited to 'src/rt/rust_run_program.cpp')
| -rw-r--r-- | src/rt/rust_run_program.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/rt/rust_run_program.cpp b/src/rt/rust_run_program.cpp index df4714758dd..848b015dd6c 100644 --- a/src/rt/rust_run_program.cpp +++ b/src/rt/rust_run_program.cpp @@ -1,5 +1,9 @@ #include "rust_internal.h" +#ifdef __APPLE__ +#include <crt_externs.h> +#endif + #if defined(__WIN32__) #include <process.h> @@ -64,7 +68,10 @@ void append_arg(char *& buf, char const *arg, bool last) { } extern "C" CDECL int -rust_run_program(const char* argv[], int in_fd, int out_fd, int err_fd) { +rust_run_program(const char* argv[], + void* envp, + const char* dir, + int in_fd, int out_fd, int err_fd) { STARTUPINFO si; ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); @@ -99,7 +106,7 @@ rust_run_program(const char* argv[], int in_fd, int out_fd, int err_fd) { PROCESS_INFORMATION pi; BOOL created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, - 0, NULL, NULL, &si, &pi); + 0, envp, dir, &si, &pi); CloseHandle(si.hStdInput); CloseHandle(si.hStdOutput); @@ -130,7 +137,10 @@ rust_process_wait(int proc) { #include <termios.h> extern "C" CDECL int -rust_run_program(char* argv[], int in_fd, int out_fd, int err_fd) { +rust_run_program(const char* argv[], + void* envp, + const char* dir, + int in_fd, int out_fd, int err_fd) { int pid = fork(); if (pid != 0) return pid; @@ -143,7 +153,18 @@ rust_run_program(char* argv[], int in_fd, int out_fd, int err_fd) { if (err_fd) dup2(err_fd, 2); /* Close all other fds. */ for (int fd = getdtablesize() - 1; fd >= 3; fd--) close(fd); - execvp(argv[0], argv); + if (dir) { chdir(dir); } + +#ifdef __APPLE__ + if (envp) { + *_NSGetEnviron() = (char **)envp; + } + execvp(argv[0], (char * const *)argv); +#else + if (!envp) { envp = environ; } + execvpe(argv[0], (char * const *)argv, (char * const *)envp); +#endif + exit(1); } |
