Signed-off-by: Andrew Gregory <[email protected]>
---
 lib/libalpm/util.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 58efa5c7..36d8a7d7 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -573,6 +573,9 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char 
*cmd, char *const argv[],
        int cwdfd;
        int retval = 0;
 
+#define HEAD 1
+#define TAIL 0
+
        /* save the cwd so we can restore it later */
        OPEN(cwdfd, ".", O_RDONLY | O_CLOEXEC);
        if(cwdfd < 0) {
@@ -617,13 +620,13 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char 
*cmd, char *const argv[],
                close(0);
                close(1);
                close(2);
-               while(dup2(child2parent_pipefd[1], 1) == -1 && errno == EINTR);
-               while(dup2(child2parent_pipefd[1], 2) == -1 && errno == EINTR);
-               while(dup2(parent2child_pipefd[0], 0) == -1 && errno == EINTR);
-               close(parent2child_pipefd[0]);
-               close(parent2child_pipefd[1]);
-               close(child2parent_pipefd[0]);
-               close(child2parent_pipefd[1]);
+               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]);
+               close(child2parent_pipefd[HEAD]);
                if(cwdfd >= 0) {
                        close(cwdfd);
                }
@@ -652,20 +655,20 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char 
*cmd, char *const argv[],
                nfds_t nfds = 2;
                struct pollfd fds[2], *child2parent = &(fds[0]), *parent2child 
= &(fds[1]);
 
-               child2parent->fd = child2parent_pipefd[0];
+               child2parent->fd = child2parent_pipefd[TAIL];
                child2parent->events = POLLIN;
                fcntl(child2parent->fd, F_SETFL, O_NONBLOCK);
-               close(child2parent_pipefd[1]);
-               close(parent2child_pipefd[0]);
+               close(child2parent_pipefd[HEAD]);
+               close(parent2child_pipefd[TAIL]);
 
                if(stdin_cb) {
-                       parent2child->fd = parent2child_pipefd[1];
+                       parent2child->fd = parent2child_pipefd[HEAD];
                        parent2child->events = POLLOUT;
                        fcntl(parent2child->fd, F_SETFL, O_NONBLOCK);
                } else {
                        parent2child->fd = -1;
                        parent2child->events = 0;
-                       close(parent2child_pipefd[1]);
+                       close(parent2child_pipefd[HEAD]);
                }
 
 #define STOP_POLLING(p) do { close(p->fd); p->fd = -1; } while(0)
-- 
2.12.2

Reply via email to