]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-pack.c: move async's #ifdef NO_PTHREADS back to run-command.c
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 3 Nov 2018 08:48:39 +0000 (09:48 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Nov 2018 04:42:11 +0000 (13:42 +0900)
On systems that do not support multithread, start_async() is
implemented with fork(). This implementation details unfortunately
leak out at least in send-pack.c [1].

To keep the code base clean of NO_PTHREADS, move the this #ifdef back
to run-command.c. The new wrapper function async_with_fork() at least
helps suggest that this special "close()" is related to async in fork
mode.

[1] 09c9957cf7 (send-pack: avoid deadlock when pack-object dies early
    - 2011-04-25)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c
run-command.h
send-pack.c

index 84b883c2132bb07bc7fa21434368d64664587b8b..3c3b8814dfc5120681f44f7451a4018c7e84f60d 100644 (file)
@@ -1246,6 +1246,15 @@ int finish_async(struct async *async)
 #endif
 }
 
+int async_with_fork(void)
+{
+#ifdef NO_PTHREADS
+       return 1;
+#else
+       return 0;
+#endif
+}
+
 const char *find_hook(const char *name)
 {
        static struct strbuf path = STRBUF_INIT;
index 9b7f38202c8b49a9f5168a1e3f1073f6ec6ca2cd..68f5369fc2d432e8b4b504e9625b541056814216 100644 (file)
@@ -141,6 +141,7 @@ struct async {
 int start_async(struct async *async);
 int finish_async(struct async *async);
 int in_async(void);
+int async_with_fork(void);
 void check_pipe(int err);
 
 /**
index e920ca57df4dd0b65d6694ed2532dead8ae83fb6..f692686770f69b49d44bf6dbabdb17886d85ea1a 100644 (file)
@@ -203,9 +203,8 @@ static int receive_status(int in, struct ref *refs)
 static int sideband_demux(int in, int out, void *data)
 {
        int *fd = data, ret;
-#ifdef NO_PTHREADS
-       close(fd[1]);
-#endif
+       if (async_with_fork())
+               close(fd[1]);
        ret = recv_sideband("send-pack", fd[0], out);
        close(out);
        return ret;