Josef Weidendorfer | b1bf95b | 2005-07-31 21:17:43 +0200 | [diff] [blame] | 1 | #ifndef RUN_COMMAND_H |
| 2 | #define RUN_COMMAND_H |
| 3 | |
Josef Weidendorfer | b1bf95b | 2005-07-31 21:17:43 +0200 | [diff] [blame] | 4 | enum { |
| 5 | ERR_RUN_COMMAND_FORK = 10000, |
| 6 | ERR_RUN_COMMAND_EXEC, |
Shawn O. Pearce | 4919bf0 | 2007-03-10 03:28:08 -0500 | [diff] [blame] | 7 | ERR_RUN_COMMAND_PIPE, |
Josef Weidendorfer | b1bf95b | 2005-07-31 21:17:43 +0200 | [diff] [blame] | 8 | ERR_RUN_COMMAND_WAITPID, |
| 9 | ERR_RUN_COMMAND_WAITPID_WRONG_PID, |
| 10 | ERR_RUN_COMMAND_WAITPID_SIGNAL, |
| 11 | ERR_RUN_COMMAND_WAITPID_NOEXIT, |
| 12 | }; |
| 13 | |
Shawn O. Pearce | f100089 | 2007-03-10 03:28:00 -0500 | [diff] [blame] | 14 | struct child_process { |
| 15 | const char **argv; |
Shawn O. Pearce | ebcb5d1 | 2007-03-10 03:28:05 -0500 | [diff] [blame] | 16 | pid_t pid; |
Shawn O. Pearce | 4919bf0 | 2007-03-10 03:28:08 -0500 | [diff] [blame] | 17 | int in; |
Shawn O. Pearce | f4bba25 | 2007-03-12 14:37:45 -0400 | [diff] [blame] | 18 | int out; |
Alex Riesen | 1568fea | 2007-05-22 23:48:23 +0200 | [diff] [blame] | 19 | const char *dir; |
Alex Riesen | ee49314 | 2007-05-22 23:48:47 +0200 | [diff] [blame] | 20 | const char *const *env; |
Shawn O. Pearce | 4919bf0 | 2007-03-10 03:28:08 -0500 | [diff] [blame] | 21 | unsigned close_in:1; |
Shawn O. Pearce | f4bba25 | 2007-03-12 14:37:45 -0400 | [diff] [blame] | 22 | unsigned close_out:1; |
Shawn O. Pearce | f100089 | 2007-03-10 03:28:00 -0500 | [diff] [blame] | 23 | unsigned no_stdin:1; |
Shawn O. Pearce | e4507ae | 2007-03-12 14:37:55 -0400 | [diff] [blame] | 24 | unsigned no_stdout:1; |
Shawn O. Pearce | f100089 | 2007-03-10 03:28:00 -0500 | [diff] [blame] | 25 | unsigned git_cmd:1; /* if this is to be git sub-command */ |
| 26 | unsigned stdout_to_stderr:1; |
| 27 | }; |
| 28 | |
Shawn O. Pearce | ebcb5d1 | 2007-03-10 03:28:05 -0500 | [diff] [blame] | 29 | int start_command(struct child_process *); |
| 30 | int finish_command(struct child_process *); |
Shawn O. Pearce | f100089 | 2007-03-10 03:28:00 -0500 | [diff] [blame] | 31 | int run_command(struct child_process *); |
| 32 | |
Shawn O. Pearce | 95d3c4f | 2006-12-30 21:55:22 -0500 | [diff] [blame] | 33 | #define RUN_COMMAND_NO_STDIN 1 |
Michal Ostrowski | 77cb17e | 2006-01-10 21:12:17 -0500 | [diff] [blame] | 34 | #define RUN_GIT_CMD 2 /*If this is to be git sub-command */ |
Shawn O. Pearce | cd83c74 | 2006-12-30 21:55:19 -0500 | [diff] [blame] | 35 | #define RUN_COMMAND_STDOUT_TO_STDERR 4 |
Shawn O. Pearce | 9b0b509 | 2006-12-30 21:55:15 -0500 | [diff] [blame] | 36 | int run_command_v_opt(const char **argv, int opt); |
Alex Riesen | 1568fea | 2007-05-22 23:48:23 +0200 | [diff] [blame] | 37 | int run_command_v_opt_cd(const char **argv, int opt, const char *dir); |
Alex Riesen | 3427b37 | 2007-05-23 22:21:39 +0200 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * env (the environment) is to be formatted like environ: "VAR=VALUE". |
| 41 | * To unset an environment variable use just "VAR". |
| 42 | */ |
Alex Riesen | ee49314 | 2007-05-22 23:48:47 +0200 | [diff] [blame] | 43 | int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env); |
Josef Weidendorfer | b1bf95b | 2005-07-31 21:17:43 +0200 | [diff] [blame] | 44 | |
| 45 | #endif |