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
,
21 int fdout
[2], fderr
[2];
22 int s0
= -1, s1
= -1, s2
= -1; /* backups of stdin, stdout, stderr */
25 const char *argv
[MAX_ARGS
];
32 reporter
*debug
= QUIETMODE
& flags
? debug_git
: debug_git_mbox
;
35 debug("[ERROR] Could not find git path");
40 if (pipe(fdout
) < 0) {
41 return -ERR_RUN_COMMAND_PIPE
;
50 if (pipe(fderr
) < 0) {
53 return -ERR_RUN_COMMAND_PIPE
;
61 va_start(params
, flags
);
63 arg
= va_arg(params
, char*);
65 } while (argc
< MAX_ARGS
&& arg
);
68 pid
= fork_process(argv
[0], argv
, working_directory
);
71 dup2(s1
, 1), close(s1
);
73 dup2(s2
, 2), close(s2
);
80 return -ERR_RUN_COMMAND_FORK
;
88 if (WAITMODE
& flags
) {
89 if (WAIT_OBJECT_0
== WaitForSingleObject((HANDLE
)pid
,
90 MAX_PROCESSING_TIME
)) {
91 if (GetExitCodeProcess((HANDLE
)pid
, &status
))
92 debug_git("Exit code: %d", status
);
94 /* play safe, and return total failure */
96 debug_git("[ERROR] GetExitCode failed (%d); "
104 strbuf_read(output
, fdout
[0], 0);
105 debug_git("STDOUT:\r\n%s\r\n*** end of STDOUT ***\r\n", output
->buf
);
109 strbuf_read(error_output
, fderr
[0], 0);
110 debug_git("STDERR:\r\n%s\r\n*** end of STDERR ***\r\n", error_output
->buf
);
113 status
= -ERR_RUN_COMMAND_WAITPID_NOEXIT
;
114 debug_git("[ERROR] process timed out; "
116 working_directory
, argv
[0]);