zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] The thing about ":|: =(hang)" (Re: [PATCH] Fix users/26150 from Etc/BUGS)
Date: Thu, 28 Apr 2022 18:43:09 -0700	[thread overview]
Message-ID: <CAH+w=7YdhSAs3A74oQSnG5Bh4wBg9PKaTRhoumt8G1XDPRdKrw@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7Zx022oxE+4RADqRAPR2=NKKcUAzrFkJseMEM06XzXyag@mail.gmail.com>

On Wed, Apr 27, 2022 at 10:24 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> The fix for
>  :|: =(nosuchcommand)
> is probably going to be similar.

As you might expect, this is a race condition.

In getoutputfile() we have:

    os = jobtab[thisjob].stat;
    waitforpid(pid, 0);
    cmdoutval = 0;
    jobtab[thisjob].stat = os;

In ":|: =(hang)", waitforpid() is looking for the PID of "=(hang)",
but both the left side of the pipe and the command substitution exit
during that wait.  This means all jobs of the right-hand-side are done
(because the right-hand side is in the current shell) so
jobtab[thisjob] should be marked STAT_DONE, but that status is
clobbered by restoring the saved state after waitforpid().

Saving and restoring the job state here dates from before we used git,
but doesn't appear to be needed any longer -- all tests still pass
with it removed.  Any ideas how to prove this wrong?

diff --git a/Src/exec.c b/Src/exec.c
index c31089bb5..f2911807c 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4883,13 +4883,9 @@ getoutputfile(char *cmd, char **eptr)
        child_unblock();
        return nam;
     } else if (pid) {
-       int os;
-
        close(fd);
-       os = jobtab[thisjob].stat;
        waitforpid(pid, 0);
        cmdoutval = 0;
-       jobtab[thisjob].stat = os;
        return nam;
     }


      reply	other threads:[~2022-04-29  1:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28  5:24 [PATCH] Fix users/26150 from Etc/BUGS Bart Schaefer
2022-04-29  1:43 ` Bart Schaefer [this message]

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='CAH+w=7YdhSAs3A74oQSnG5Bh4wBg9PKaTRhoumt8G1XDPRdKrw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.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.
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).