mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-07 01:05:39 +03:00
Make process-spawning take environments and working directories, remove procsrv task from compiletest.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user