Skip to content

Commit 1b19fa4

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 959e2e6 commit 1b19fa4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

builtin-upload-archive.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,17 @@ static void error_clnt(const char *fmt, ...)
8080
die("sent error to the client: %s", buf);
8181
}
8282

83-
static void process_input(int child_fd, int band)
83+
static ssize_t process_input(int child_fd, int band)
8484
{
8585
char buf[16384];
8686
ssize_t sz = read(child_fd, buf, sizeof(buf));
8787
if (sz < 0) {
8888
if (errno != EAGAIN && errno != EINTR)
8989
error_clnt("read error: %s\n", strerror(errno));
90-
return;
90+
return sz;
9191
}
9292
send_sideband(1, band, buf, sz, LARGE_PACKET_MAX);
93+
return sz;
9394
}
9495

9596
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)
131132

132133
while (1) {
133134
struct pollfd pfd[2];
135+
ssize_t processed[2] = { 0, 0 };
134136
int status;
135137

136138
pfd[0].fd = fd1[0];
@@ -147,12 +149,12 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
147149
}
148150
if (pfd[0].revents & POLLIN)
149151
/* Data stream ready */
150-
process_input(pfd[0].fd, 1);
152+
processed[0] = process_input(pfd[0].fd, 1);
151153
if (pfd[1].revents & POLLIN)
152154
/* Status stream ready */
153-
process_input(pfd[1].fd, 2);
155+
processed[1] = process_input(pfd[1].fd, 2);
154156
/* Always finish to read data when available */
155-
if ((pfd[0].revents | pfd[1].revents) & POLLIN)
157+
if (processed[0] || processed[1])
156158
continue;
157159

158160
if (waitpid(writer, &status, 0) < 0)

0 commit comments

Comments
 (0)