Lines Matching refs:cmd

29 int start_command(struct child_process *cmd)  in start_command()  argument
40 need_in = !cmd->no_stdin && cmd->in < 0; in start_command()
43 if (cmd->out > 0) in start_command()
44 close(cmd->out); in start_command()
47 cmd->in = fdin[1]; in start_command()
50 need_out = !cmd->no_stdout in start_command()
51 && !cmd->stdout_to_stderr in start_command()
52 && cmd->out < 0; in start_command()
57 else if (cmd->in) in start_command()
58 close(cmd->in); in start_command()
61 cmd->out = fdout[0]; in start_command()
64 need_err = !cmd->no_stderr && cmd->err < 0; in start_command()
69 else if (cmd->in) in start_command()
70 close(cmd->in); in start_command()
73 else if (cmd->out) in start_command()
74 close(cmd->out); in start_command()
77 cmd->err = fderr[0]; in start_command()
81 cmd->pid = fork(); in start_command()
82 if (!cmd->pid) { in start_command()
83 if (cmd->no_stdin) in start_command()
88 } else if (cmd->in) { in start_command()
89 dup2(cmd->in, 0); in start_command()
90 close(cmd->in); in start_command()
93 if (cmd->no_stderr) in start_command()
100 if (cmd->no_stdout) in start_command()
102 else if (cmd->stdout_to_stderr) in start_command()
107 } else if (cmd->out > 1) { in start_command()
108 dup2(cmd->out, 1); in start_command()
109 close(cmd->out); in start_command()
112 if (cmd->dir && chdir(cmd->dir)) in start_command()
113 die("exec %s: cd to %s failed (%s)", cmd->argv[0], in start_command()
114 cmd->dir, str_error_r(errno, sbuf, sizeof(sbuf))); in start_command()
115 if (cmd->env) { in start_command()
116 for (; *cmd->env; cmd->env++) { in start_command()
117 if (strchr(*cmd->env, '=')) in start_command()
118 putenv((char*)*cmd->env); in start_command()
120 unsetenv(*cmd->env); in start_command()
123 if (cmd->preexec_cb) in start_command()
124 cmd->preexec_cb(); in start_command()
125 if (cmd->exec_cmd) { in start_command()
126 execv_cmd(cmd->argv); in start_command()
128 execvp(cmd->argv[0], (char *const*) cmd->argv); in start_command()
133 if (cmd->pid < 0) { in start_command()
137 else if (cmd->in) in start_command()
138 close(cmd->in); in start_command()
141 else if (cmd->out) in start_command()
142 close(cmd->out); in start_command()
152 else if (cmd->in) in start_command()
153 close(cmd->in); in start_command()
157 else if (cmd->out) in start_command()
158 close(cmd->out); in start_command()
200 int finish_command(struct child_process *cmd) in finish_command() argument
202 return wait_or_whine(cmd->pid); in finish_command()
205 int run_command(struct child_process *cmd) in run_command() argument
207 int code = start_command(cmd); in run_command()
210 return finish_command(cmd); in run_command()
213 static void prepare_run_command_v_opt(struct child_process *cmd, in prepare_run_command_v_opt() argument
217 memset(cmd, 0, sizeof(*cmd)); in prepare_run_command_v_opt()
218 cmd->argv = argv; in prepare_run_command_v_opt()
219 cmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0; in prepare_run_command_v_opt()
220 cmd->exec_cmd = opt & RUN_EXEC_CMD ? 1 : 0; in prepare_run_command_v_opt()
221 cmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0; in prepare_run_command_v_opt()
226 struct child_process cmd; in run_command_v_opt() local
227 prepare_run_command_v_opt(&cmd, argv, opt); in run_command_v_opt()
228 return run_command(&cmd); in run_command_v_opt()