Lines Matching refs:cmd

18 int start_command(struct child_process *cmd)  in start_command()  argument
28 need_in = !cmd->no_stdin && cmd->in < 0; in start_command()
31 if (cmd->out > 0) in start_command()
32 close(cmd->out); in start_command()
35 cmd->in = fdin[1]; in start_command()
38 need_out = !cmd->no_stdout in start_command()
39 && !cmd->stdout_to_stderr in start_command()
40 && cmd->out < 0; in start_command()
45 else if (cmd->in) in start_command()
46 close(cmd->in); in start_command()
49 cmd->out = fdout[0]; in start_command()
52 need_err = !cmd->no_stderr && cmd->err < 0; in start_command()
57 else if (cmd->in) in start_command()
58 close(cmd->in); in start_command()
61 else if (cmd->out) in start_command()
62 close(cmd->out); in start_command()
65 cmd->err = fderr[0]; in start_command()
69 cmd->pid = fork(); in start_command()
70 if (!cmd->pid) { in start_command()
71 if (cmd->no_stdin) in start_command()
76 } else if (cmd->in) { in start_command()
77 dup2(cmd->in, 0); in start_command()
78 close(cmd->in); in start_command()
81 if (cmd->no_stderr) in start_command()
88 if (cmd->no_stdout) in start_command()
90 else if (cmd->stdout_to_stderr) in start_command()
95 } else if (cmd->out > 1) { in start_command()
96 dup2(cmd->out, 1); in start_command()
97 close(cmd->out); in start_command()
100 if (cmd->dir && chdir(cmd->dir)) in start_command()
101 die("exec %s: cd to %s failed (%s)", cmd->argv[0], in start_command()
102 cmd->dir, strerror(errno)); in start_command()
103 if (cmd->env) { in start_command()
104 for (; *cmd->env; cmd->env++) { in start_command()
105 if (strchr(*cmd->env, '=')) in start_command()
106 putenv((char*)*cmd->env); in start_command()
108 unsetenv(*cmd->env); in start_command()
111 if (cmd->preexec_cb) in start_command()
112 cmd->preexec_cb(); in start_command()
113 if (cmd->perf_cmd) { in start_command()
114 execv_perf_cmd(cmd->argv); in start_command()
116 execvp(cmd->argv[0], (char *const*) cmd->argv); in start_command()
121 if (cmd->pid < 0) { in start_command()
125 else if (cmd->in) in start_command()
126 close(cmd->in); in start_command()
129 else if (cmd->out) in start_command()
130 close(cmd->out); in start_command()
140 else if (cmd->in) in start_command()
141 close(cmd->in); in start_command()
145 else if (cmd->out) in start_command()
146 close(cmd->out); in start_command()
185 int finish_command(struct child_process *cmd) in finish_command() argument
187 return wait_or_whine(cmd->pid); in finish_command()
190 int run_command(struct child_process *cmd) in run_command() argument
192 int code = start_command(cmd); in run_command()
195 return finish_command(cmd); in run_command()
198 static void prepare_run_command_v_opt(struct child_process *cmd, in prepare_run_command_v_opt() argument
202 memset(cmd, 0, sizeof(*cmd)); in prepare_run_command_v_opt()
203 cmd->argv = argv; in prepare_run_command_v_opt()
204 cmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0; in prepare_run_command_v_opt()
205 cmd->perf_cmd = opt & RUN_PERF_CMD ? 1 : 0; in prepare_run_command_v_opt()
206 cmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0; in prepare_run_command_v_opt()
211 struct child_process cmd; in run_command_v_opt() local
212 prepare_run_command_v_opt(&cmd, argv, opt); in run_command_v_opt()
213 return run_command(&cmd); in run_command_v_opt()