upload-archive: fix infinite loop on Cygwin
On Cygwin, poll() reports POLLIN even for file descriptors that have reached their end. This caused git upload-archive to be stuck in an infinite loop, as it only looked at the POLLIN flag. In addition to POLLIN, check if read() returned 0, which indicates end-of-file, and keep looping only as long as at least one of the file descriptors has input. This lets the following command finish on its own when run in a git repository on Cygwin, instead of it getting stuck after printing all file names: $ git archive -v --remote . HEAD >/dev/null Reported-by: Bob Kagy <bobkagy@gmail.com> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jun 17, 2009 at 12:11 UTC
1b19fa46344f512949270dc88089574950519ea3
1 file changed
+7
-5
builtin-upload-archive.c
+7
-5
@@ -80,16 +80,17 @@ static void error_clnt(const char *fmt, ...)
80
die("sent error to the client: %s", buf);
81
}
82
83
-static void process_input(int child_fd, int band)
83
+static ssize_t process_input(int child_fd, int band)
84
{
85
char buf[16384];
86
ssize_t sz = read(child_fd, buf, sizeof(buf));
87
if (sz < 0) {
88
if (errno != EAGAIN && errno != EINTR)
89
error_clnt("read error: %s\n", strerror(errno));
90
- return;
90
+ return sz;
91
}
92
send_sideband(1, band, buf, sz, LARGE_PACKET_MAX);
93
+ return sz;
94
}
95
96
int cmd_upload_archive(int argc, const char **argv, const char *prefix)
@@ -131,6 +132,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
132
133
while (1) {
134
struct pollfd pfd[2];
135
+ ssize_t processed[2] = { 0, 0 };
136
int status;
137
138
pfd[0].fd = fd1[0];
@@ -147,12 +149,12 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
149
}
150
if (pfd[0].revents & POLLIN)
151
/* Data stream ready */
150
- process_input(pfd[0].fd, 1);
152
+ processed[0] = process_input(pfd[0].fd, 1);
153
if (pfd[1].revents & POLLIN)
154
/* Status stream ready */
153
- process_input(pfd[1].fd, 2);
155
+ processed[1] = process_input(pfd[1].fd, 2);
156
/* Always finish to read data when available */
155
- if ((pfd[0].revents | pfd[1].revents) & POLLIN)
157
+ if (processed[0] || processed[1])
158
continue;
159
160
if (waitpid(writer, &status, 0) < 0)