git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Franck Bui-Huu <vagabon.xyz@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/3] Add sideband status report to git-archive protocol
Date: Tue, 12 Sep 2006 00:24:39 -0700	[thread overview]
Message-ID: <7vzmd5eedk.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <45053BA2.6050502@innova-card.com> (Franck Bui-Huu's message of "Mon, 11 Sep 2006 12:34:10 +0200")

Franck Bui-Huu <vagabon.xyz@gmail.com> writes:

> I get a lot of "Hmph, HUP?" messages when testing "git-archive
> --remote" command. One guess: this can be due to the fact that when
> the writer process exits, it first closes its fd but do not send a
> SIGCHLD signal right after to its parent.

It does not reproduce for me, but the code I have is obviously
bogus in a few places.

 - When POLLHUP is set, it goes ahead and reads the file
   descriptor.  Worse yet, it does not check the return value of
   read() for errors when it does.

 - When we processed one POLLIN, we should just go back and see
   if any more data is available.  We can check if the child is
   still there when poll gave control back at us but without any
   actual input as you said.

I was uncomfortable letting waitpid() there to wait forever.
When does poll() return?  (1) we have data ready in which case
we process; (2) the child somehow closed the pipe but without
dying, which is an error in the child.  In the latter case even
not hanging in waitpid() and retrying the poll would not give
any useful input so that would not help either.

So I think your patch is a correct fix, except that I think we
should let the remote side know why we stopped talking to them
instead of calling die() there.

We should also check when read() returns an error, so how about
this on top of your patch?

diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c
index 2ebe9a0..a53cfee 100644
--- a/builtin-upload-archive.c
+++ b/builtin-upload-archive.c
@@ -16,6 +16,9 @@ static const char upload_archive_usage[]
 static const char deadchild[] =
 "git-upload-archive: archiver died with error";
 
+static const char lostchild[] =
+"git-upload-archive: archiver process was lost";
+
 
 static int run_upload_archive(int argc, const char **argv, const char *prefix)
 {
@@ -73,6 +76,31 @@ static int run_upload_archive(int argc, 
 	return ar.write_archive(&ar.args);
 }
 
+static void error_clnt(const char *fmt, ...)
+{
+	char buf[1024];
+	va_list params;
+	int len;
+
+	va_start(params, fmt);
+	len = vsprintf(buf, fmt, params);
+	va_end(params);
+	send_sideband(1, 3, buf, len, LARGE_PACKET_MAX);
+	die("sent error to the client: %s", buf);
+}
+
+static void process_input(int child_fd, int band)
+{
+	char buf[16384];
+	ssize_t sz = read(child_fd, buf, sizeof(buf));
+	if (sz < 0) {
+		if (errno != EINTR)
+			error_clnt("read error: %s\n", strerror(errno));
+	}
+	else if (sz)
+		send_sideband(1, band, buf, sz, LARGE_PACKET_MAX);
+}
+
 int cmd_upload_archive(int argc, const char **argv, const char *prefix)
 {
 	pid_t writer;
@@ -112,8 +140,6 @@ int cmd_upload_archive(int argc, const c
 
 	while (1) {
 		struct pollfd pfd[2];
-		char buf[16384];
-		ssize_t sz;
 		int status;
 
 		pfd[0].fd = fd1[0];
@@ -128,26 +154,19 @@ int cmd_upload_archive(int argc, const c
 			}
 			continue;
 		}
-		if (pfd[0].revents & (POLLIN|POLLHUP)) {
+		if (pfd[0].revents & POLLIN)
 			/* Data stream ready */
-			sz = read(pfd[0].fd, buf, sizeof(buf));
-			send_sideband(1, 1, buf, sz, LARGE_PACKET_MAX);
-		}
-		if (pfd[1].revents & (POLLIN|POLLHUP)) {
+			process_input(pfd[0].fd, 1);
+		if (pfd[1].revents & POLLIN)
 			/* Status stream ready */
-			sz = read(pfd[1].fd, buf, sizeof(buf));
-			send_sideband(1, 2, buf, sz, LARGE_PACKET_MAX);
-		}
-
+			process_input(pfd[1].fd, 2);
 		if ((pfd[0].revents | pfd[1].revents) == POLLIN)
 			continue;
 
-		if (waitpid(writer, &status, 0) < 0) {
-			die("waitpid failed: %s", strerror(errno));
-		}
-		if (!WIFEXITED(status) || WEXITSTATUS(status) > 0)
-			send_sideband(1, 3, deadchild, strlen(deadchild),
-				      LARGE_PACKET_MAX);
+		if (waitpid(writer, &status, 0) < 0)
+			error_clnt("%s", lostchild);
+		else if (!WIFEXITED(status) || WEXITSTATUS(status) > 0)
+			error_clnt("%s", deadchild);
 		packet_flush(1);
 		break;
 	}

  reply	other threads:[~2006-09-12  7:23 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-10  7:09 [PATCH 1/2] archive: allow remote to have more formats than we understand Junio C Hamano
2006-09-10  7:12 ` [PATCH 2/2] Add --verbose to git-archive Junio C Hamano
2006-09-10 10:36   ` [PATCH 1/3] Move sideband client side support into reusable form Junio C Hamano
2006-09-10 19:15     ` Franck Bui-Huu
2006-09-10 10:37   ` [PATCH] Move sideband server " Junio C Hamano
2006-09-10 10:47   ` [PATCH 3/3] Add sideband status report to git-archive protocol Junio C Hamano
2006-09-10 15:58     ` [PATCH] git-upload-archive: add config option to allow only specified formats Rene Scharfe
2006-09-10 16:12       ` Rene Scharfe
2006-09-10 18:00       ` Junio C Hamano
2006-09-11 21:41         ` Rene Scharfe
2006-09-11 21:50           ` Jakub Narebski
2006-09-10 19:07       ` Franck Bui-Huu
2006-09-11 21:55         ` Rene Scharfe
2006-09-10 19:15     ` [PATCH 3/3] Add sideband status report to git-archive protocol Franck Bui-Huu
2006-09-10 20:31       ` Junio C Hamano
2006-09-11 10:34     ` Franck Bui-Huu
2006-09-12  7:24       ` Junio C Hamano [this message]
2006-09-12  8:17         ` Franck Bui-Huu
2006-09-12  8:45           ` Franck Bui-Huu
2006-09-12  9:00             ` [PATCH] connect.c: finish_connect(): allow null pid parameter Franck Bui-Huu
2006-09-13  4:48               ` Junio C Hamano
2006-09-13  8:26                 ` [PATCH] Test return value of finish_connect() Franck Bui-Huu
2006-09-13  8:32                 ` [PATCH] git_connect: change return type to pid_t Franck Bui-Huu
2006-09-12 23:44           ` [PATCH 3/3] Add sideband status report to git-archive protocol Junio C Hamano
2006-09-10 12:05 ` [PATCH 1/2] archive: allow remote to have more formats than we understand Rene Scharfe
2006-09-10 19:02 ` Franck Bui-Huu
2006-09-10 19:07   ` Junio C Hamano
2006-09-10 19:18     ` Franck Bui-Huu

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=7vzmd5eedk.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    --cc=vagabon.xyz@gmail.com \
    /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).