0001
0002 #ifndef __SUBCMD_RUN_COMMAND_H
0003 #define __SUBCMD_RUN_COMMAND_H
0004
0005 #include <unistd.h>
0006
0007 enum {
0008 ERR_RUN_COMMAND_FORK = 10000,
0009 ERR_RUN_COMMAND_EXEC,
0010 ERR_RUN_COMMAND_PIPE,
0011 ERR_RUN_COMMAND_WAITPID,
0012 ERR_RUN_COMMAND_WAITPID_WRONG_PID,
0013 ERR_RUN_COMMAND_WAITPID_SIGNAL,
0014 ERR_RUN_COMMAND_WAITPID_NOEXIT,
0015 };
0016 #define IS_RUN_COMMAND_ERR(x) (-(x) >= ERR_RUN_COMMAND_FORK)
0017
0018 struct child_process {
0019 const char **argv;
0020 pid_t pid;
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 int in;
0040 int out;
0041 int err;
0042 const char *dir;
0043 const char *const *env;
0044 unsigned no_stdin:1;
0045 unsigned no_stdout:1;
0046 unsigned no_stderr:1;
0047 unsigned exec_cmd:1;
0048 unsigned stdout_to_stderr:1;
0049 void (*preexec_cb)(void);
0050 };
0051
0052 int start_command(struct child_process *);
0053 int finish_command(struct child_process *);
0054 int run_command(struct child_process *);
0055
0056 #define RUN_COMMAND_NO_STDIN 1
0057 #define RUN_EXEC_CMD 2
0058 #define RUN_COMMAND_STDOUT_TO_STDERR 4
0059 int run_command_v_opt(const char **argv, int opt);
0060
0061 #endif