]> asedeno.scripts.mit.edu Git - git.git/commitdiff
send-pack: fix pipeline.
authorJunio C Hamano <junkio@cox.net>
Fri, 29 Dec 2006 10:35:40 +0000 (02:35 -0800)
committerJunio C Hamano <junkio@cox.net>
Fri, 29 Dec 2006 19:37:01 +0000 (11:37 -0800)
send-pack builds a pipeline that runs "rev-list | pack-objects"
and sends the output from pack-objects to the other side, while
feeding the input side of that pipe from itself.  However, the
file descriptor that is given to this pipeline (so that it can
be dup2(2)'ed into file descriptor 1 of pack-objects) is closed
by the caller before the complex fork+exec dance!  Worse yet,
the caller already dup2's it to 1, so the child process did not
even have to.

I do not understand how this code could possibly have been
working, but it somehow was working by accident.

Merging the sliding mmap() code reveals this problem, presumably
because it keeps one extra file descriptor open for a packfile
and changes the way file descriptors are allocated.  I am too
tired to diagnose the problem now, but this seems to be a
sensible fix.

Signed-off-by: Junio C Hamano <junkio@cox.net>
send-pack.c

index cc884f3b2debbaadfc3c42cda20074257fa48a65..54de96e40c36428373b21f3dec4939cef767a900 100644 (file)
@@ -58,7 +58,7 @@ static void exec_rev_list(struct ref *refs)
 /*
  * Run "rev-list --stdin | pack-objects" pipe.
  */
-static void rev_list(int fd, struct ref *refs)
+static void rev_list(struct ref *refs)
 {
        int pipe_fd[2];
        pid_t pack_objects_pid;
@@ -71,10 +71,8 @@ static void rev_list(int fd, struct ref *refs)
                 * and writes to the original fd
                 */
                dup2(pipe_fd[0], 0);
-               dup2(fd, 1);
                close(pipe_fd[0]);
                close(pipe_fd[1]);
-               close(fd);
                exec_pack_objects();
                die("pack-objects setup failed");
        }
@@ -85,7 +83,6 @@ static void rev_list(int fd, struct ref *refs)
        dup2(pipe_fd[1], 1);
        close(pipe_fd[0]);
        close(pipe_fd[1]);
-       close(fd);
        exec_rev_list(refs);
 }
 
@@ -111,7 +108,7 @@ static void rev_list_generate(int fd, struct ref *refs)
                close(pipe_fd[0]);
                close(pipe_fd[1]);
                close(fd);
-               rev_list(fd, refs);
+               rev_list(refs);
                die("rev-list setup failed");
        }
        if (rev_list_generate_pid < 0)