Windows doesn't have O_NONBLOCK nor F_GETFL defined, so we need cannot run
in parallel there. Instead the children will output directly to our stderr
and we run one child at a time.

Bonus: We are setting process.err = -1; which we previously expected the
get_next_task callback to do. It is easy to forget that part in the callback
leading to hard to debug errors.

Signed-off-by: Stefan Beller <[email protected]>
---
 run-command.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/run-command.c b/run-command.c
index 86fbe50..19de253 100644
--- a/run-command.c
+++ b/run-command.c
@@ -958,6 +958,10 @@ static struct parallel_processes *pp_init(int n,
        if (n < 1)
                n = online_cpus();
 
+#if !(defined (O_NONBLOCK) && defined (F_GETFL))
+       n = 1;
+#endif
+
        pp->max_processes = n;
        pp->data = data;
        if (!get_next_task)
@@ -1006,6 +1010,7 @@ static void pp_cleanup(struct parallel_processes *pp)
        sigchain_pop_common();
 }
 
+#if defined (O_NONBLOCK) && defined (F_GETFL)
 static void set_nonblocking_or_die(int fd)
 {
        int flags = fcntl(fd, F_GETFL);
@@ -1014,6 +1019,7 @@ static void set_nonblocking_or_die(int fd)
        else if (fcntl(fd, F_SETFL, flags | O_NONBLOCK))
                die("Could not set file status flags");
 }
+#endif
 
 /* returns
  *  0 if a new task was started.
@@ -1031,6 +1037,12 @@ static int pp_start_one(struct parallel_processes *pp)
        if (i == pp->max_processes)
                die("BUG: bookkeeping is hard");
 
+#if defined (O_NONBLOCK) && defined (F_GETFL)
+       pp->children[i].process.err = -1;
+#else
+       pp->children[i].process.err = 2;
+#endif
+
        if (!pp->get_next_task(&pp->children[i].data,
                               &pp->children[i].process,
                               &pp->children[i].err,
@@ -1049,8 +1061,9 @@ static int pp_start_one(struct parallel_processes *pp)
                strbuf_reset(&pp->children[i].err);
                return code ? -1 : 1;
        }
-
+#if defined (O_NONBLOCK) && defined (F_GETFL)
        set_nonblocking_or_die(pp->children[i].process.err);
+#endif
 
        pp->nr_processes++;
        pp->children[i].in_use = 1;
-- 
2.6.1.247.ge8f2a41.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to