提交 9c95fbf9 编写于 作者: F Franck Bui-Huu 提交者: Junio C Hamano

upload-archive: monitor child communication even more carefully.

The current code works like this: if others flags than POLLIN is
raised we assume that (a) something bad happened and the child died or
(b) the child has closed the pipe because it had no more data to send.

For the latter case, we assume wrongly that one call to
process_input() will empty the pipe. Indeed it reads only 16Ko of data
by call and the the pipe capacity can be larger than that (on current
Linux kernel, it is 65536 bytes). Therefore the child can write 32ko
of data, for example, and close the pipe. After that poll will return
POLLIN _and_ POLLHUP and the parent will read only 16ko of data.

This patch forces the parent to empty the pipe as soon as POLLIN is
raised and even if POLLHUP or something else is raised too.

Moreover, some implementations of poll might return POLLRDNORM flag
even if it is non standard.
Signed-off-by: NFranck Bui-Huu <vagabon.xyz@gmail.com>
Signed-off-by: NJunio C Hamano <junkio@cox.net>
上级 4d69065d
...@@ -160,7 +160,8 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix) ...@@ -160,7 +160,8 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
if (pfd[1].revents & POLLIN) if (pfd[1].revents & POLLIN)
/* Status stream ready */ /* Status stream ready */
process_input(pfd[1].fd, 2); process_input(pfd[1].fd, 2);
if ((pfd[0].revents | pfd[1].revents) == POLLIN) /* Always finish to read data when available */
if ((pfd[0].revents | pfd[1].revents) & POLLIN)
continue; continue;
if (waitpid(writer, &status, 0) < 0) if (waitpid(writer, &status, 0) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册