zsh-workers
 help / color / mirror / code / Atom feed
From: John Buddery <jvb@cyberscience.com>
To: Peter Stephenson <pws@csr.com>
Cc: Zsh-Workers <zsh-workers@sunsite.dk>
Subject: Re: Subshell with multios causes hang
Date: Wed, 23 May 2007 12:25:13 +0100	[thread overview]
Message-ID: <1179919513.3015.569.camel@aston.uk.cyberscience.com> (raw)
In-Reply-To: <20070523111203.299233ec@news01.csr.com>

On Wed, 2007-05-23 at 11:12 +0100, Peter Stephenson wrote:
> On Tue, 22 May 2007 18:29:25 +0100
> Peter Stephenson <pws@csr.com> wrote:
> > On Tue, 22 May 2007 12:21:43 +0100
> > John Buddery <jvb@cyberscience.com> wrote:
> > > Essentially I run the equivalent of:
> > > 
> > >    ( echo hello ) >| /tmp/out >| /tmp/out2
> > > 
> > > and in an interactive shell (or any with job control) this hangs.
> >...
> > Wossgoingon?
> >...
> > I'll carry on looking at this when I get a chance, but for now I'm
> > confused enough to go to the beer festival.
> 
> Success, I think.  The answer started to come to me in the queue.  John
> sent me another email; the basic problem seems to be the obscure
> interaction between forking, job control and multios in this case.
> 

Excellent, works for me - thanks very much!

If you're interested while you're dealing with multios, there was one
other fault I noticed when digging around: with an input multios, there
is a race condition after the fork in closemn() between the addproc()
and the child process exiting. If the child multios exits (having sent
it's output to the buffered pipe) before the addproc(), the shell hangs
later when it tries to wait for the already-exited pid.

This can be reproduced fairly reliably with the example you posted last
year:

% echo This is the file >file
% fn() { cat; }
% fn <$(echo file file)
This is the file
This is the file
(hang at this point)

One way to fix it would be to block the child signal until the child pid was registered (patch below).
Admittedly it's a bit obscure, though - not that my last example wasn't...

Thanks,

John

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.111
diff -u -r1.111 exec.c
--- Src/exec.c  8 May 2007 10:02:59 -0000       1.111
+++ Src/exec.c  23 May 2007 11:09:53 -0000
@@ -1549,20 +1549,24 @@
        pid_t pid;
        struct timeval bgtime;
 
+        child_block();
        if ((pid = zfork(&bgtime))) {
            for (i = 0; i < mn->ct; i++)
                zclose(mn->fds[i]);
            zclose(mn->pipe);
            if (pid == -1) { 
                mfds[fd] = NULL;
+                child_unblock();
                return;
            }
            mn->ct = 1;
            mn->fds[0] = fd;
            addproc(pid, NULL, 1, &bgtime);
+            child_unblock();
            return;
        }
        /* pid == 0 */
+        child_unblock();
        closeallelse(mn);
        if (mn->rflag) {
            /* tee process */




  reply	other threads:[~2007-05-23 11:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-22 11:21 John Buddery
2007-05-22 17:29 ` Peter Stephenson
2007-05-23 10:12   ` Peter Stephenson
2007-05-23 11:25     ` John Buddery [this message]
2007-05-23 11:50       ` Peter Stephenson
2007-05-23 15:00     ` Bart Schaefer

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=1179919513.3015.569.camel@aston.uk.cyberscience.com \
    --to=jvb@cyberscience.com \
    --cc=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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.
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).