git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Tony Finch <dot@dotat.at>
Cc: Bob Kagy <bobkagy@gmail.com>, git@vger.kernel.org
Subject: Re: git archive, cygwin, and --git-dir vs --remote
Date: Thu, 21 May 2009 16:29:42 +0200	[thread overview]
Message-ID: <4A156556.900@lsrfire.ath.cx> (raw)
In-Reply-To: <alpine.LSU.2.00.0905211431060.23478@hermes-2.csi.cam.ac.uk>

Tony Finch schrieb:
> 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.

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

  reply	other threads:[~2009-05-21 14:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 14:37 git archive, cygwin, and --git-dir vs --remote Bob Kagy
2009-05-21  9:08 ` René Scharfe
2009-05-21 13:32   ` Tony Finch
2009-05-21 14:29     ` René Scharfe [this message]
2009-06-17 10:11       ` [PATCH] upload-archive: fix infinite loop on Cygwin René Scharfe
2009-06-18 17:18         ` Tony Finch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A156556.900@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=bobkagy@gmail.com \
    --cc=dot@dotat.at \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).