zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: ignore EINTR in ztcp/zsocket accept()
@ 2015-08-10 10:22 Joshua Krusell
  2015-08-10 11:33 ` Peter Stephenson
  2015-08-10 12:18 ` Oliver Kiddle
  0 siblings, 2 replies; 5+ messages in thread
From: Joshua Krusell @ 2015-08-10 10:22 UTC (permalink / raw)
  To: zsh-workers

Interrupting `ztcp -a` causes zsh to exit immediately. Would it be
appropriate to just ignore EINTR?
/jsks

diff --git a/Src/Modules/socket.c b/Src/Modules/socket.c
index cd56d46..92d0a50 100644
--- a/Src/Modules/socket.c
+++ b/Src/Modules/socket.c
@@ -191,8 +191,11 @@ bin_zsocket(char *nam, char **args, Options ops, UNUSED(int func))
 	}
 
 	len = sizeof(soun);
-	if ((rfd = accept(lfd, (struct sockaddr *)&soun, &len)) == -1)
-	{
+	do {
+	    rfd = accept(lfd, (struct sockaddr *)&soun, &len);
+	} while (errno == EINTR && !errflag);
+
+	if (rfd == -1) {
 	    zwarnnam(nam, "could not accept connection: %e", errno);
 	    return 1;
 	}
diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c
index d5b62a8..3049273 100644
--- a/Src/Modules/tcp.c
+++ b/Src/Modules/tcp.c
@@ -536,8 +536,11 @@ bin_ztcp(char *nam, char **args, Options ops, UNUSED(int func))
 	sess = zts_alloc(ZTCP_INBOUND);
 
 	len = sizeof(sess->peer.in);
-	if ((rfd = accept(lfd, (struct sockaddr *)&sess->peer.in, &len)) == -1)
-	{
+	do {
+	    rfd = accept(lfd, (struct sockaddr *)&sess->peer.in, &len);
+	} while (errno == EINTR && !errflag);
+
+	if (rfd == -1) {
 	    zwarnnam(nam, "could not accept connection: %e", errno);
 	    tcp_close(sess);
 	    return 1;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: ignore EINTR in ztcp/zsocket accept()
  2015-08-10 10:22 PATCH: ignore EINTR in ztcp/zsocket accept() Joshua Krusell
@ 2015-08-10 11:33 ` Peter Stephenson
  2015-08-10 12:18 ` Oliver Kiddle
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2015-08-10 11:33 UTC (permalink / raw)
  To: zsh-workers

On Mon, 10 Aug 2015 12:22:12 +0200
Joshua Krusell <js.shirin@gmail.com> wrote:
> Interrupting `ztcp -a` causes zsh to exit immediately. Would it be
> appropriate to just ignore EINTR?

That seems reasonable, and consistent with numerous other bits of IO
code.  I've pushed it.

Thanks
pws


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: ignore EINTR in ztcp/zsocket accept()
  2015-08-10 10:22 PATCH: ignore EINTR in ztcp/zsocket accept() Joshua Krusell
  2015-08-10 11:33 ` Peter Stephenson
@ 2015-08-10 12:18 ` Oliver Kiddle
  2015-08-10 12:31   ` Peter Stephenson
  2015-08-10 14:30   ` Joshua Krusell
  1 sibling, 2 replies; 5+ messages in thread
From: Oliver Kiddle @ 2015-08-10 12:18 UTC (permalink / raw)
  To: Joshua Krusell; +Cc: Zsh workers

Joshua Krusell wrote:
> -	{
> +	do {
> +	    rfd = accept(lfd, (struct sockaddr *)&soun, &len);
> +	} while (errno == EINTR && !errflag);

On success, errno is not set to zero. So if it happens to have a stray
value of EINTR before the loop, this could loop despite accept having
succeeded. Shouldn't rfd == -1 also be included in the condition?

Oliver


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: ignore EINTR in ztcp/zsocket accept()
  2015-08-10 12:18 ` Oliver Kiddle
@ 2015-08-10 12:31   ` Peter Stephenson
  2015-08-10 14:30   ` Joshua Krusell
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2015-08-10 12:31 UTC (permalink / raw)
  To: Oliver Kiddle, Zsh workers

On Mon, 10 Aug 2015 14:18:59 +0200
Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
> Joshua Krusell wrote:
> > -	{
> > +	do {
> > +	    rfd = accept(lfd, (struct sockaddr *)&soun, &len);
> > +	} while (errno == EINTR && !errflag);
> 
> On success, errno is not set to zero. So if it happens to have a stray
> value of EINTR before the loop, this could loop despite accept having
> succeeded. Shouldn't rfd == -1 also be included in the condition?

Yes, you're right.

pws


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: ignore EINTR in ztcp/zsocket accept()
  2015-08-10 12:18 ` Oliver Kiddle
  2015-08-10 12:31   ` Peter Stephenson
@ 2015-08-10 14:30   ` Joshua Krusell
  1 sibling, 0 replies; 5+ messages in thread
From: Joshua Krusell @ 2015-08-10 14:30 UTC (permalink / raw)
  To: Zsh workers

On 10/08/15 at 02:18P, Oliver Kiddle wrote:
> Joshua Krusell wrote:
> > -	{
> > +	do {
> > +	    rfd = accept(lfd, (struct sockaddr *)&soun, &len);
> > +	} while (errno == EINTR && !errflag);
> 
> On success, errno is not set to zero. So if it happens to have a stray
> value of EINTR before the loop, this could loop despite accept having
> succeeded. Shouldn't rfd == -1 also be included in the condition?
> 
> Oliver

Right, of course...thanks!
/jsks


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-10 14:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10 10:22 PATCH: ignore EINTR in ztcp/zsocket accept() Joshua Krusell
2015-08-10 11:33 ` Peter Stephenson
2015-08-10 12:18 ` Oliver Kiddle
2015-08-10 12:31   ` Peter Stephenson
2015-08-10 14:30   ` Joshua Krusell

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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