Thread (6 messages) flat view 6 messages, 3 authors, 2016-06-15

Re: git archive, cygwin, and --git-dir vs --remote

From: René Scharfe <hidden>
Date: 2016-06-15 22:46:48
Subsystem: the rest · Maintainer: Linus Torvalds

Tony Finch schrieb:
On Thu, 21 May 2009, René Scharfe wrote:
quoted
That's strange.  It seems that poll() reports that there is data to read
from the child (which is running git-upload-archive), even though it
already called exit().
Poll reports an FD is readable when it reaches EOF.
OK, makes sense.  I still don't understand why upload-archive doesn't get
into an infinite loop on Linux (Fedora 10), though.
quoted
The following patch works around this issue by terminating the otherwise
endless loop after read() returned nothing for the thousandth time in a
row.
You should stop reading the first time read() returns 0 i.e. EOF.
Thanks.  In that case the following patch is better.


 builtin-upload-archive.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c
index 0206b41..a3fa5b3 100644
--- a/builtin-upload-archive.c
+++ b/builtin-upload-archive.c
@@ -80,16 +80,19 @@ static void error_clnt(const char *fmt, ...)
 	die("sent error to the client: %s", buf);
 }
 
-static void process_input(int child_fd, int band)
+static int process_input(int child_fd, int band)
 {
 	char buf[16384];
 	ssize_t sz = read(child_fd, buf, sizeof(buf));
+	if (sz == 0)
+		return EOF;
 	if (sz < 0) {
 		if (errno != EAGAIN && errno != EINTR)
 			error_clnt("read error: %s\n", strerror(errno));
-		return;
+		return 0;
 	}
 	send_sideband(1, band, buf, sz, LARGE_PACKET_MAX);
+	return 0;
 }
 
 int cmd_upload_archive(int argc, const char **argv, const char *prefix)
@@ -131,7 +134,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
 
 	while (1) {
 		struct pollfd pfd[2];
-		int status;
+		int status, both_at_eof = EOF;
 
 		pfd[0].fd = fd1[0];
 		pfd[0].events = POLLIN;
@@ -147,12 +150,12 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
 		}
 		if (pfd[0].revents & POLLIN)
 			/* Data stream ready */
-			process_input(pfd[0].fd, 1);
+			both_at_eof &= process_input(pfd[0].fd, 1);
 		if (pfd[1].revents & POLLIN)
 			/* Status stream ready */
-			process_input(pfd[1].fd, 2);
+			both_at_eof &= process_input(pfd[1].fd, 2);
 		/* Always finish to read data when available */
-		if ((pfd[0].revents | pfd[1].revents) & POLLIN)
+		if (!both_at_eof)
 			continue;
 
 		if (waitpid(writer, &status, 0) < 0)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help