Esempio n. 1
0
static void vg_cleanup_env(void)
{
    HChar **envp = (HChar**)*_NSGetEnviron();
    env_unsetenv(envp, "VALGRIND_LAUNCHER");
    env_unsetenv(envp, "DYLD_SHARED_REGION");
    // GrP fixme should be more like mash_colon_env()
    env_unsetenv(envp, "DYLD_INSERT_LIBRARIES");
}   
Esempio n. 2
0
int start_command(struct child_process *cmd)
{
	int need_in, need_out;
	int fdin[2] = { -1, -1 };
	int fdout[2] = { -1, -1 };
	const char **env = (const char **)environ;

	need_in = !cmd->no_stdin && cmd->in < 0;
	if (need_in) {
		if (pipe(fdin) < 0)
			return -ERR_RUN_COMMAND_PIPE;
		cmd->in = fdin[1];
		cmd->close_in = 1;
	}

	need_out = !cmd->no_stdout
		&& !cmd->stdout_to_stderr
		&& cmd->out < 0;
	if (need_out) {
		if (pipe(fdout) < 0) {
			if (need_in)
				close_pair(fdin);
			return -ERR_RUN_COMMAND_PIPE;
		}
		cmd->out = fdout[0];
		cmd->close_out = 1;
	}

	{
		if (cmd->no_stdin)
			fdin[0] = open("/dev/null", O_RDWR);
		else if (need_in) {
			/* nothing */
		} else if (cmd->in) {
			fdin[0] = cmd->in;
		}

		if (cmd->no_stdout)
			fdout[1] = open("/dev/null", O_RDWR);
		else if (cmd->stdout_to_stderr)
			fdout[1] = dup(2);
		else if (need_out) {
			/* nothing */
		} else if (cmd->out > 1) {
			fdout[1] = cmd->out;
		}

		if (cmd->dir)
			die("chdir in start_command() not implemented");
		if (cmd->dir && chdir(cmd->dir))
			die("exec %s: cd to %s failed (%s)", cmd->argv[0],
			    cmd->dir, strerror(errno));
		if (cmd->env) {
			if (cmd->merge_env) {
				env = copy_environ();
				for (; *cmd->env; cmd->env++) {
					if (strchr(*cmd->env, '='))
						die("setting environment in start_command() not implemented");
					else
						env_unsetenv(env, *cmd->env);
				}
			}
			else
				env = cmd->env;
		}
		if (cmd->git_cmd) {
			cmd->pid = spawnve_git_cmd(cmd->argv, fdin, fdout, env);
		} else {
			cmd->pid = spawnvpe_pipe(cmd->cmd ? cmd->cmd : cmd->argv[0], cmd->argv, env, fdin, fdout);
		}
	}
	if (cmd->pid < 0) {
		if (need_in)
			close_pair(fdin);
		if (need_out)
			close_pair(fdout);
		return -ERR_RUN_COMMAND_FORK;
	}

	return 0;
}