| 1565 | } |
| 1566 | |
| 1567 | static void pp_init(struct parallel_processes *pp, |
| 1568 | const struct run_process_parallel_opts *opts, |
| 1569 | struct parallel_processes_for_signal *pp_sig) |
| 1570 | { |
| 1571 | const size_t n = opts->processes; |
| 1572 | |
| 1573 | if (!n) |
| 1574 | BUG("you must provide a non-zero number of processes!"); |
| 1575 | |
| 1576 | trace_printf("run_processes_parallel: preparing to run up to %"PRIuMAX" tasks", |
| 1577 | (uintmax_t)n); |
| 1578 | |
| 1579 | if (!opts->get_next_task) |
| 1580 | BUG("you need to specify a get_next_task function"); |
| 1581 | |
| 1582 | CALLOC_ARRAY(pp->children, n); |
| 1583 | if (!opts->ungroup) |
| 1584 | CALLOC_ARRAY(pp->pfd, n * 2); |
| 1585 | |
| 1586 | for (size_t i = 0; i < n; i++) { |
| 1587 | strbuf_init(&pp->children[i].err, 0); |
| 1588 | child_process_init(&pp->children[i].process); |
| 1589 | if (pp->pfd) { |
| 1590 | pp->pfd[i].events = POLLIN | POLLHUP; |
| 1591 | pp->pfd[i].fd = -1; |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | pp_sig->pp = pp; |
| 1596 | pp_sig->opts = opts; |
| 1597 | pp_for_signal = pp_sig; |
| 1598 | sigchain_push_common(handle_children_on_signal); |
| 1599 | } |
| 1600 | |
| 1601 | static void pp_cleanup(struct parallel_processes *pp, |
| 1602 | const struct run_process_parallel_opts *opts) |
no test coverage detected