git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
May 21, 2009, 14:29 UTC
Message-ID
<4A156556.900@lsrfire.ath.cx>
In-Reply-To
<alpine.LSU.2.00.0905211431060.23478@hermes-2.csi.cam.ac.uk>
Tony Finch schrieb:
Show 6 quoted lines
> On Thu, 21 May 2009, René Scharfe wrote:
>> 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.

Show 5 quoted lines
>> 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)
Previous: Tony FinchNext: René Scharfe
Message 4 of 6 in “git archive, cygwin, and --git-dir vs --remote”
  1. Bob KagyMay 18, 2009
  2. René ScharfeMay 21, 2009
  3. Tony FinchMay 21, 2009
  4. René ScharfeMay 21, 2009
  5. upload-archive: fix infinite loop on CygwinRené Scharfe, Jun 17, 2009
  6. Tony FinchJun 18, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.