git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Franck Bui-Huu <vagabon.xyz@gmail.com>
To: Junio C Hamano <junkio@cox.net>
Cc: Franck Bui-Huu <vagabon.xyz@gmail.com>,
	git@vger.kernel.org, Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Subject: Re: [PATCH 3/3] Add sideband status report to git-archive protocol
Date: Mon, 11 Sep 2006 12:34:10 +0200	[thread overview]
Message-ID: <45053BA2.6050502@innova-card.com> (raw)
In-Reply-To: <7v1wqkt2v4.fsf_-_@assigned-by-dhcp.cox.net>

Junio C Hamano wrote:
> Using the refactored sideband code from existing upload-pack protocol,
> this lets the error condition and status output sent from the remote
> process to be shown locally.
> 
> Signed-off-by: Junio C Hamano <junkio@cox.net>
> ---

[snip]

> -}
> +	while (1) {
> +		struct pollfd pfd[2];
> +		char buf[16384];
> +		ssize_t sz;
> +		pid_t pid;
> +		int status;
> +
> +		pfd[0].fd = fd1[0];
> +		pfd[0].events = POLLIN;
> +		pfd[1].fd = fd2[0];
> +		pfd[1].events = POLLIN;
> +		if (poll(pfd, 2, -1) < 0) {
> +			if (errno != EINTR) {
> +				error("poll failed resuming: %s",
> +				      strerror(errno));
> +				sleep(1);
> +			}
> +			continue;
> +		}
> +		if (pfd[0].revents & (POLLIN|POLLHUP)) {
> +			/* Data stream ready */
> +			sz = read(pfd[0].fd, buf, sizeof(buf));
> +			send_sideband(1, 1, buf, sz, DEFAULT_PACKET_MAX);
> +		}
> +		if (pfd[1].revents & (POLLIN|POLLHUP)) {
> +			/* Status stream ready */
> +			sz = read(pfd[1].fd, buf, sizeof(buf));
> +			send_sideband(1, 2, buf, sz, DEFAULT_PACKET_MAX);
> +		}
>  
> +		if (((pfd[0].revents | pfd[1].revents) & POLLHUP) == 0)
> +			continue;
> +		/* did it die? */
> +		pid = waitpid(writer, &status, WNOHANG);
> +		if (!pid) {
> +			fprintf(stderr, "Hmph, HUP?\n");
> +			continue;
> +		}

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.

Therefore poll() can return POLLHUP flag to the parent process but
waitpid still returns 0 because the writer process has still not sent
SIGCHLD signal to its parent.

How about this patch ? If poll() doesn't only return the single POLLIN
flag, then either the pipe has been closed because the write process
died or something wrong happened. In all these cases we can wait for
the writer process to exit then die.

-- >8 --

diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c
index 42cb9f8..2ebe9a0 100644
--- a/builtin-upload-archive.c
+++ b/builtin-upload-archive.c
@@ -114,7 +114,6 @@ int cmd_upload_archive(int argc, const c
 		struct pollfd pfd[2];
 		char buf[16384];
 		ssize_t sz;
-		pid_t pid;
 		int status;
 
 		pfd[0].fd = fd1[0];
@@ -140,13 +139,11 @@ int cmd_upload_archive(int argc, const c
 			send_sideband(1, 2, buf, sz, LARGE_PACKET_MAX);
 		}
 
-		if (((pfd[0].revents | pfd[1].revents) & POLLHUP) == 0)
-			continue;
-		/* did it die? */
-		pid = waitpid(writer, &status, WNOHANG);
-		if (!pid) {
-			fprintf(stderr, "Hmph, HUP?\n");
+		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),

  parent reply	other threads:[~2006-09-11 10:34 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 [this message]
2006-09-12  7:24       ` Junio C Hamano
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=45053BA2.6050502@innova-card.com \
    --to=vagabon.xyz@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=rene.scharfe@lsrfire.ath.cx \
    /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).