1 #include "git-compat-util.h"
5 #include "systeminfo.h"
8 #define MAX_PROCESSING_TIME (60 * 1000)
11 /* copy from run-command.c */
12 static inline void close_pair(int fd
[2])
18 int exec_program(const char *working_directory
,
19 struct strbuf
*output
, struct strbuf
*error_output
,
23 const char *argv
[MAX_ARGS
];
27 va_start(params
, flags
);
29 arg
= va_arg(params
, char*);
31 } while (argc
< MAX_ARGS
&& arg
);
34 return exec_program_v(working_directory
, output
, error_output
,
38 int exec_program_v(const char *working_directory
,
39 struct strbuf
*output
, struct strbuf
*error_output
,
40 int flags
, const char **argv
)
42 int fdout
[2], fderr
[2];
43 int s1
= -1, s2
= -1; /* backups of stdin, stdout, stderr */
49 reporter
*debug
= QUIETMODE
& flags
? debug_git
: debug_git_mbox
;
52 debug("[ERROR] Could not find git path");
57 if (pipe(fdout
) < 0) {
58 return -ERR_RUN_COMMAND_PIPE
;
67 if (pipe(fderr
) < 0) {
70 return -ERR_RUN_COMMAND_PIPE
;
78 pid
= fork_process(argv
[0], argv
, working_directory
);
81 dup2(s1
, 1), close(s1
);
83 dup2(s2
, 2), close(s2
);
90 return -ERR_RUN_COMMAND_FORK
;
98 if (WAITMODE
& flags
) {
99 ret
= wait_for_process(pid
, MAX_PROCESSING_TIME
,
103 debug_git("[ERROR] wait_for_process failed (%d); "
113 strbuf_read(output
, fdout
[0], 0);
114 debug_git("STDOUT:\r\n%s\r\n*** end of STDOUT ***\r\n", output
->buf
);
118 strbuf_read(error_output
, fderr
[0], 0);
119 debug_git("STDERR:\r\n%s\r\n*** end of STDERR ***\r\n", error_output
->buf
);
122 status
= -ERR_RUN_COMMAND_WAITPID_NOEXIT
;
123 debug_git("[ERROR] process timed out; "
125 working_directory
, argv
[0]);