4 #include "systeminfo.h"
7 #define MAX_PROCESSING_TIME (60 * 1000)
10 /* copy from run-command.c */
11 static inline void close_pair(int fd
[2])
17 int exec_program(const char *working_directory
,
18 struct strbuf
*output
, struct strbuf
*error_output
,
22 const char *argv
[MAX_ARGS
];
26 va_start(params
, flags
);
28 arg
= va_arg(params
, char*);
30 } while (argc
< MAX_ARGS
&& arg
);
33 return exec_program_v(working_directory
, output
, error_output
,
37 int exec_program_v(const char *working_directory
,
38 struct strbuf
*output
, struct strbuf
*error_output
,
39 int flags
, const char **argv
)
41 int fdout
[2], fderr
[2];
42 int s0
= -1, s1
= -1, s2
= -1; /* backups of stdin, stdout, stderr */
48 reporter
*debug
= QUIETMODE
& flags
? debug_git
: debug_git_mbox
;
51 debug("[ERROR] Could not find git path");
56 if (pipe(fdout
) < 0) {
57 return -ERR_RUN_COMMAND_PIPE
;
66 if (pipe(fderr
) < 0) {
69 return -ERR_RUN_COMMAND_PIPE
;
77 pid
= fork_process(argv
[0], argv
, working_directory
);
80 dup2(s1
, 1), close(s1
);
82 dup2(s2
, 2), close(s2
);
89 return -ERR_RUN_COMMAND_FORK
;
97 if (WAITMODE
& flags
) {
98 ret
= wait_for_process(pid
, MAX_PROCESSING_TIME
,
102 debug_git("[ERROR] wait_for_process failed (%d); "
112 strbuf_read(output
, fdout
[0], 0);
113 debug_git("STDOUT:\r\n%s\r\n*** end of STDOUT ***\r\n", output
->buf
);
117 strbuf_read(error_output
, fderr
[0], 0);
118 debug_git("STDERR:\r\n%s\r\n*** end of STDERR ***\r\n", error_output
->buf
);
121 status
= -ERR_RUN_COMMAND_WAITPID_NOEXIT
;
122 debug_git("[ERROR] process timed out; "
124 working_directory
, argv
[0]);