Newer
Older
Dan Johansen
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 299d287e..358b97c6 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -635,21 +635,33 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[],
if(pid == 0) {
/* this code runs for the child only (the actual chroot/exec) */
- close(0);
- close(1);
- close(2);
- while(dup2(child2parent_pipefd[HEAD], 1) == -1 && errno == EINTR);
- while(dup2(child2parent_pipefd[HEAD], 2) == -1 && errno == EINTR);
- while(dup2(parent2child_pipefd[TAIL], 0) == -1 && errno == EINTR);
- close(parent2child_pipefd[TAIL]);
close(parent2child_pipefd[HEAD]);
close(child2parent_pipefd[TAIL]);
+ while(dup2(child2parent_pipefd[HEAD], STDERR_FILENO) == -1) {
+ if(errno != EINTR) {
+ /* at this point, the child cannot talk through the parent */
+ exit(1);
+ }
+ }
+ while(dup2(parent2child_pipefd[TAIL], STDIN_FILENO) == -1) {
+ if(errno != EINTR) {
+ /* use fprintf() instead of _alpm_log() to send output through the parent */
+ fprintf(stderr, _("could not redirect standard input (%s)\n"), strerror(errno));
+ exit(1);
+ }
+ }
+ close(parent2child_pipefd[TAIL]);
+ while(dup2(child2parent_pipefd[HEAD], STDOUT_FILENO) == -1) {
+ if(errno != EINTR) {
+ fprintf(stderr, _("could not redirect standard output (%s)\n"), strerror(errno));
+ exit(1);
+ }
+ }
close(child2parent_pipefd[HEAD]);
if(cwdfd >= 0) {
close(cwdfd);
}
- /* use fprintf instead of _alpm_log to send output through the parent */
if(chroot(handle->root) != 0) {
fprintf(stderr, _("could not change the root directory (%s)\n"), strerror(errno));
exit(1);