1
2 #ifndef __SUBCMD_RUN_COMMAND_H
3 #define __SUBCMD_RUN_COMMAND_H
4
5 #include <unistd.h>
6
7 enum {
8 ERR_RUN_COMMAND_FORK = 10000,
9 ERR_RUN_COMMAND_EXEC,
10 ERR_RUN_COMMAND_PIPE,
11 ERR_RUN_COMMAND_WAITPID,
12 ERR_RUN_COMMAND_WAITPID_WRONG_PID,
13 ERR_RUN_COMMAND_WAITPID_SIGNAL,
14 ERR_RUN_COMMAND_WAITPID_NOEXIT,
15 };
16 #define IS_RUN_COMMAND_ERR(x) (-(x) >= ERR_RUN_COMMAND_FORK)
17
18 struct child_process {
19 const char **argv;
20 pid_t pid;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 int in;
40 int out;
41 int err;
42 const char *dir;
43 const char *const *env;
44 unsigned no_stdin:1;
45 unsigned no_stdout:1;
46 unsigned no_stderr:1;
47 unsigned exec_cmd:1;
48 unsigned stdout_to_stderr:1;
49 void (*preexec_cb)(void);
50 };
51
52 int start_command(struct child_process *);
53 int finish_command(struct child_process *);
54 int run_command(struct child_process *);
55
56 #define RUN_COMMAND_NO_STDIN 1
57 #define RUN_EXEC_CMD 2
58 #define RUN_COMMAND_STDOUT_TO_STDERR 4
59 int run_command_v_opt(const char **argv, int opt);
60
61 #endif