From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: Possible signal handling issues
Date: Thu, 2 Jan 2014 21:55:05 +0000 [thread overview]
Message-ID: <20140102215505.323946ce@pws-pc.ntlworld.com> (raw)
In-Reply-To: <131228150234.ZM27671@torch.brasslantern.com>
On Sat, 28 Dec 2013 15:02:34 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> Both of these have been around since at least 4.2.0. Consider this script:
>
> --- snip ---
> sleep 20 &
> TRAPINT() { set -x; kill -INT $$ }
> wait
> --- snip ---
>
> Run that in the foreground, kill it with ctrl+c, and watch the infinite
> loop. Something to do with the "wait" command allows the INT to be re-
> queued for handling even when it is sent from inside an INT trap. The
> signal_suspend() in zwaitjob() is constantly re-interrupted and never
> returns.
The following doesn't get us much further, but I'm not sure executing
"wait" is the key thing here: I think it might be more to do with the
fact that the job was first started in the background. The following is
less than conclusive, however, since "fg" shares a lot of code with "wait".
I first tried modifying the above to
set -x # for earlier (de?)mystification
sleep 20 &
TRAPINT() { set -x; kill -INT $$ }
fg
and then running with "zsh -fi" (something in my startup files is
causing a hang without the -f, which is irrelevant, but that's why I
went on and tried the other version below before I found that out). I
got
../zwaitjob2.sh:3:> sleep 20
../zwaitjob2.sh:5:> fg %sleep
[1] + 1792 running sleep 20
^C reproducibly gives
+TRAPINT:0> set -x
+TRAPINT:0> kill -INT 2004
+TRAPINT:0> set -x
+TRAPINT:0> kill -INT 2004
Then I tried:
set -x
print $$
setopt monitor
sleep 20 &
TRAPINT() { set -x; kill -INT $$ }
fg %sleep
Initially I got
+../zwaitjob3.sh:2> print 1907
1907
+../zwaitjob3.sh:3> setopt monitor
[1] 1910
+../zwaitjob3.sh:4> sleep 20
+../zwaitjob3.sh:6> fg %sleep
[1] + running sleep 20
This time ^C or "kill -INT 1907" doesn't do anything. I'm not sure what's
going on here. However, if I send "kill -INT 1910" (killing the forked
process) from outside I see some variable number of repetitions of
+TRAPINT:0> kill -INT 1922
+TRAPINT:0> set -x
and then the shell exits.
Consequently, this looks to me like some intrinsic race that happens to
be particularly reproducible in the "wait" case. However, this still
seems to be different to the second problem.
I wondered whether the race was due to the places where signals were
being queued and unqueued, but haven't got anywhere down that route, and
I don't know why this is different when the process wasn't
backgrounded. I have a vague memory we do something about blocking ^C
when starting a job in the background, though?
pws
next prev parent reply other threads:[~2014-01-02 21:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-28 23:02 Bart Schaefer
2014-01-02 21:55 ` Peter Stephenson [this message]
2014-01-02 22:40 ` Peter Stephenson
2014-01-02 22:53 ` Peter Stephenson
2014-01-03 7:52 ` Bart Schaefer
2014-01-03 17:44 ` Peter Stephenson
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=20140102215505.323946ce@pws-pc.ntlworld.com \
--to=p.w.stephenson@ntlworld.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).