MCPcopy Index your code
hub / github.com/git/git / pp_buffer_io

Function pp_buffer_io

run-command.c:1729–1796  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1727}
1728
1729static void pp_buffer_io(struct parallel_processes *pp,
1730 const struct run_process_parallel_opts *opts,
1731 int timeout)
1732{
1733 /* for each potential child slot, prepare two pollfd entries */
1734 for (size_t i = 0; i < opts->processes; i++) {
1735 if (child_is_sending_output(&pp->children[i])) {
1736 pp->pfd[2*i].fd = pp->children[i].process.err;
1737 pp->pfd[2*i].events = POLLIN | POLLHUP;
1738 } else {
1739 pp->pfd[2*i].fd = -1;
1740 }
1741
1742 if (child_is_receiving_input(&pp->children[i])) {
1743 pp->pfd[2*i+1].fd = pp->children[i].process.in;
1744 pp->pfd[2*i+1].events = POLLOUT;
1745 } else {
1746 pp->pfd[2*i+1].fd = -1;
1747 }
1748 }
1749
1750 while (poll(pp->pfd, opts->processes * 2, timeout) < 0) {
1751 if (errno == EINTR)
1752 continue;
1753 pp_cleanup(pp, opts);
1754 die_errno("poll");
1755 }
1756
1757 for (size_t i = 0; i < opts->processes; i++) {
1758 /* Handle input feeding (stdin) */
1759 if (pp->pfd[2*i+1].revents & (POLLOUT | POLLHUP | POLLERR)) {
1760 if (opts->feed_pipe) {
1761 int ret = opts->feed_pipe(pp->children[i].process.in,
1762 opts->data,
1763 pp->children[i].data);
1764 if (ret < 0)
1765 die_errno("feed_pipe");
1766 if (ret) {
1767 /* done feeding */
1768 close(pp->children[i].process.in);
1769 pp->children[i].process.in = 0;
1770 }
1771 } else {
1772 /*
1773 * No feed_pipe means there is nothing to do, so
1774 * close the fd. Child input can be fed by other
1775 * methods, such as opts->path_to_stdin which
1776 * slurps a file via dup2, so clean up here.
1777 */
1778 close(pp->children[i].process.in);
1779 pp->children[i].process.in = 0;
1780 }
1781 }
1782
1783 /* Handle output reading (stderr) */
1784 if (child_is_working(&pp->children[i]) &&
1785 pp->pfd[2*i].revents & (POLLIN | POLLHUP)) {
1786 int n = strbuf_read_once(&pp->children[i].err,

Callers 1

pp_handle_child_IOFunction · 0.85

Calls 7

child_is_sending_outputFunction · 0.85
child_is_receiving_inputFunction · 0.85
pollFunction · 0.85
pp_cleanupFunction · 0.85
die_errnoFunction · 0.85
child_is_workingFunction · 0.85
strbuf_read_onceFunction · 0.85

Tested by

no test coverage detected