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 /* see winexec.c for the Windows-specific implementation of exec_program_v() */
40 int exec_program_v(const char *working_directory
,
41 struct strbuf
*output
, struct strbuf
*error_output
,
42 int flags
, const char **argv
)
44 int fdout
[2], fderr
[2];
45 int s1
= -1, s2
= -1; /* backups of stdin, stdout, stderr */
52 reporter
*debug
= QUIETMODE
& flags
? _debug_git
: _debug_git_mbox
;
55 debug("[ERROR] Could not find git path");
59 if ((!output
|| !error_output
) && !(DETACHMODE
& flags
))
60 devnull
= open("/dev/null", O_WRONLY
);
64 if (pipe(fdout
) < 0) {
65 return -ERR_RUN_COMMAND_PIPE
;
70 } else if (devnull
>= 0) {
76 if (pipe(fderr
) < 0) {
79 return -ERR_RUN_COMMAND_PIPE
;
84 } else if (devnull
>= 0) {
90 pid
= fork_process(argv
[0], argv
, working_directory
);
93 dup2(s1
, 1), close(s1
);
95 dup2(s2
, 2), close(s2
);
102 return -ERR_RUN_COMMAND_FORK
;
110 if (WAITMODE
& flags
) {
111 ret
= wait_for_process(pid
, MAX_PROCESSING_TIME
,
115 debug_git("[ERROR] wait_for_process failed (%d); "
125 strbuf_read(output
, fdout
[0], 0);
126 debug_git("STDOUT:\r\n%s\r\n*** end of STDOUT ***\r\n", output
->buf
);
130 strbuf_read(error_output
, fderr
[0], 0);
131 debug_git("STDERR:\r\n%s\r\n*** end of STDERR ***\r\n", error_output
->buf
);
134 status
= -ERR_RUN_COMMAND_WAITPID_NOEXIT
;
135 debug_git("[ERROR] process timed out; "
137 working_directory
, argv
[0]);