Lines Matching refs:cmd
19 int start_command(struct child_process *cmd) in start_command() argument
30 need_in = !cmd->no_stdin && cmd->in < 0; in start_command()
33 if (cmd->out > 0) in start_command()
34 close(cmd->out); in start_command()
37 cmd->in = fdin[1]; in start_command()
40 need_out = !cmd->no_stdout in start_command()
41 && !cmd->stdout_to_stderr in start_command()
42 && cmd->out < 0; in start_command()
47 else if (cmd->in) in start_command()
48 close(cmd->in); in start_command()
51 cmd->out = fdout[0]; in start_command()
54 need_err = !cmd->no_stderr && cmd->err < 0; in start_command()
59 else if (cmd->in) in start_command()
60 close(cmd->in); in start_command()
63 else if (cmd->out) in start_command()
64 close(cmd->out); in start_command()
67 cmd->err = fderr[0]; in start_command()
71 cmd->pid = fork(); in start_command()
72 if (!cmd->pid) { in start_command()
73 if (cmd->no_stdin) in start_command()
78 } else if (cmd->in) { in start_command()
79 dup2(cmd->in, 0); in start_command()
80 close(cmd->in); in start_command()
83 if (cmd->no_stderr) in start_command()
90 if (cmd->no_stdout) in start_command()
92 else if (cmd->stdout_to_stderr) in start_command()
97 } else if (cmd->out > 1) { in start_command()
98 dup2(cmd->out, 1); in start_command()
99 close(cmd->out); in start_command()
102 if (cmd->dir && chdir(cmd->dir)) in start_command()
103 die("exec %s: cd to %s failed (%s)", cmd->argv[0], in start_command()
104 cmd->dir, strerror_r(errno, sbuf, sizeof(sbuf))); in start_command()
105 if (cmd->env) { in start_command()
106 for (; *cmd->env; cmd->env++) { in start_command()
107 if (strchr(*cmd->env, '=')) in start_command()
108 putenv((char*)*cmd->env); in start_command()
110 unsetenv(*cmd->env); in start_command()
113 if (cmd->preexec_cb) in start_command()
114 cmd->preexec_cb(); in start_command()
115 if (cmd->perf_cmd) { in start_command()
116 execv_perf_cmd(cmd->argv); in start_command()
118 execvp(cmd->argv[0], (char *const*) cmd->argv); in start_command()
123 if (cmd->pid < 0) { in start_command()
127 else if (cmd->in) in start_command()
128 close(cmd->in); in start_command()
131 else if (cmd->out) in start_command()
132 close(cmd->out); in start_command()
142 else if (cmd->in) in start_command()
143 close(cmd->in); in start_command()
147 else if (cmd->out) in start_command()
148 close(cmd->out); in start_command()
190 int finish_command(struct child_process *cmd) in finish_command() argument
192 return wait_or_whine(cmd->pid); in finish_command()
195 int run_command(struct child_process *cmd) in run_command() argument
197 int code = start_command(cmd); in run_command()
200 return finish_command(cmd); in run_command()
203 static void prepare_run_command_v_opt(struct child_process *cmd, in prepare_run_command_v_opt() argument
207 memset(cmd, 0, sizeof(*cmd)); in prepare_run_command_v_opt()
208 cmd->argv = argv; in prepare_run_command_v_opt()
209 cmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0; in prepare_run_command_v_opt()
210 cmd->perf_cmd = opt & RUN_PERF_CMD ? 1 : 0; in prepare_run_command_v_opt()
211 cmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0; in prepare_run_command_v_opt()
216 struct child_process cmd; in run_command_v_opt() local
217 prepare_run_command_v_opt(&cmd, argv, opt); in run_command_v_opt()
218 return run_command(&cmd); in run_command_v_opt()