run-command: move wait_or_whine earlier
We want to reuse it from start_command. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Jan 10, 2010 at 14:08 UTC
ab0b41daf62ec3076e980fcad492b1997b35f22b
1 file changed
+42
-42
run-command.c
+42
-42
@@ -39,6 +39,48 @@ static inline void set_cloexec(int fd)
39
}
40
#endif
41
42
+static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
43
+{
44
+ int status, code = -1;
45
+ pid_t waiting;
46
+ int failed_errno = 0;
47
+
48
+ while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
49
+ ; /* nothing */
50
+
51
+ if (waiting < 0) {
52
+ failed_errno = errno;
53
+ error("waitpid for %s failed: %s", argv0, strerror(errno));
54
+ } else if (waiting != pid) {
55
+ error("waitpid is confused (%s)", argv0);
56
+ } else if (WIFSIGNALED(status)) {
57
+ code = WTERMSIG(status);
58
+ error("%s died of signal %d", argv0, code);
59
+ /*
60
+ * This return value is chosen so that code & 0xff
61
+ * mimics the exit code that a POSIX shell would report for
62
+ * a program that died from this signal.
63
+ */
64
+ code -= 128;
65
+ } else if (WIFEXITED(status)) {
66
+ code = WEXITSTATUS(status);
67
+ /*
68
+ * Convert special exit code when execvp failed.
69
+ */
70
+ if (code == 127) {
71
+ code = -1;
72
+ failed_errno = ENOENT;
73
+ if (!silent_exec_failure)
74
+ error("cannot run %s: %s", argv0,
75
+ strerror(ENOENT));
76
+ }
77
+ } else {
78
+ error("waitpid is confused (%s)", argv0);
79
+ }
80
+ errno = failed_errno;
81
+ return code;
82
+}
83
+
84
int start_command(struct child_process *cmd)
85
{
86
int need_in, need_out, need_err;
@@ -272,48 +314,6 @@ fail_pipe:
314
return 0;
315
}
316
275
-static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
276
-{
277
- int status, code = -1;
278
- pid_t waiting;
279
- int failed_errno = 0;
280
-
281
- while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
282
- ; /* nothing */
283
-
284
- if (waiting < 0) {
285
- failed_errno = errno;
286
- error("waitpid for %s failed: %s", argv0, strerror(errno));
287
- } else if (waiting != pid) {
288
- error("waitpid is confused (%s)", argv0);
289
- } else if (WIFSIGNALED(status)) {
290
- code = WTERMSIG(status);
291
- error("%s died of signal %d", argv0, code);
292
- /*
293
- * This return value is chosen so that code & 0xff
294
- * mimics the exit code that a POSIX shell would report for
295
- * a program that died from this signal.
296
- */
297
- code -= 128;
298
- } else if (WIFEXITED(status)) {
299
- code = WEXITSTATUS(status);
300
- /*
301
- * Convert special exit code when execvp failed.
302
- */
303
- if (code == 127) {
304
- code = -1;
305
- failed_errno = ENOENT;
306
- if (!silent_exec_failure)
307
- error("cannot run %s: %s", argv0,
308
- strerror(ENOENT));
309
- }
310
- } else {
311
- error("waitpid is confused (%s)", argv0);
312
- }
313
- errno = failed_errno;
314
- return code;
315
-}
316
-
317
int finish_command(struct child_process *cmd)
318
{
319
return wait_or_whine(cmd->pid, cmd->argv[0], cmd->silent_exec_failure);