Line 0
Link Here
|
|
|
1 |
--- ./tools/unix/process.c.orig 2011-09-06 09:43:42.000000000 +0100 |
2 |
+++ ./tools/unix/process.c 2011-11-17 15:30:00.000000000 +0000 |
3 |
@@ -38,7 +38,9 @@ |
4 |
|
5 |
#include <unistd.h> |
6 |
#include <errno.h> |
7 |
+#ifdef HAVE_SPAWN_H |
8 |
#include <spawn.h> |
9 |
+#endif |
10 |
#include <sys/wait.h> |
11 |
|
12 |
#include "common.h" |
13 |
@@ -46,6 +48,7 @@ |
14 |
|
15 |
extern char **environ; |
16 |
|
17 |
+#ifdef HAVE_SPAWN_H |
18 |
void pipeline(const char *const *argv, struct pipeline *pl) |
19 |
{ |
20 |
posix_spawn_file_actions_t file_acts; |
21 |
@@ -75,6 +78,36 @@ |
22 |
|
23 |
pl->infd = pipefds[1]; |
24 |
} |
25 |
+#else |
26 |
+void pipeline(const char * const *argv, struct pipeline *pl) |
27 |
+{ |
28 |
+ int pipefds[2]; |
29 |
+ if (pipe(pipefds)) |
30 |
+ die_errno(errno, "pipe"); |
31 |
+ |
32 |
+ pl->pid = fork(); |
33 |
+ |
34 |
+ if (pl->pid == -1) |
35 |
+ die_errno(errno, "fork: %s", argv[0]); |
36 |
+ else |
37 |
+ if (pl->pid == 0) { |
38 |
+ if (dup2(pipefds[0], 0)) |
39 |
+ die_errno(errno, "dup2()"); |
40 |
+ if (close(pipefds[0])) |
41 |
+ die_errno(errno, "close()"); |
42 |
+ if (close(pipefds[1])) |
43 |
+ die_errno(errno, "close()"); |
44 |
+ execvp(argv[0], argv); |
45 |
+ die_errno(errno, "execvp()"); |
46 |
+ } |
47 |
+ else { |
48 |
+ if (close(pipefds[0])) |
49 |
+ die_errno(errno, "close"); |
50 |
+ } |
51 |
+ |
52 |
+ pl->infd = pipefds[1]; |
53 |
+} |
54 |
+#endif |
55 |
|
56 |
int finish_pipeline(struct pipeline *pl) |
57 |
{ |