Skip to content
Snippets Groups Projects
0003-fix-execution-of-pacman-hooks.patch 1.64 KiB
Newer Older
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);