From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Peter Stephenson <p.w.stephenson@ntlworld.com>
Cc: zsh-workers@zsh.org
Subject: Re: Bug with traps and exit
Date: Mon, 16 Dec 2019 05:24:23 +0000 [thread overview]
Message-ID: <20191216052423.svgnhfkpsxh46a6j@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <c5dab7f1a18c7021e0ebc0314c15f0f9c960b3f4.camel@ntlworld.com>
Peter,
Thanks for all the details.
I'm afraid there are two distinct bugs being discussed in this thread. One is
workers/44922, which you analyzed in detail. I'll follow up about that one
with Martijn. However, the bug I was confused about how to get started on is
workers/44007 (also in this thread):
> trap 'printf $1; exit; printf $2' USR1
> fn() {
> printf 1
> kill -s usr1 $$
> printf 2
> }
> printf 0
> fn A B
> printf 3
Here, Martijn was saying that zsh should print 01A but in fact prints 01A2.
This suggests the 'exit' inhibits «printf $2» and «printf 3» from running, but
doesn't inhibit «printf 2» (without a dollar sign) from running. How would
you approach something like this? I'm guessing bin_exit should set a global
volatile int variable to '1' if it's called from a signal handler, but where
would that variable be checked?
Thanks,
Daniel
Peter Stephenson wrote on Sun, Dec 15, 2019 at 18:59:21 +0000:
> On Sat, 2019-12-14 at 11:28 +0000, Daniel Shahaf wrote:
> > Peter Stephenson wrote on Fri, Dec 13, 2019 at 14:49:40 +0000:
> > > As you know, getting anyone interested in looking at things is very
> > > difficult. I'm taking more of a back seat myself, unless I can see
> > > something glaring. Anyone is more than welcome to jump in while
> > > the old guard is still looking on to help.
> >
> > I don't know about others, but I'm not even sure where to begin fixing this.
> > I can find the code handling traps easily enough ('intrap', etc), and I know
> > where the code handling functions is (doshfunc()), but how to proceed? Would
> > the right fix be to add some code in the end of runshfunc(), after
> > unqueue_signals(), that checks whether a trap has been executed and called
> > 'exit'…?
>
> OK, so this is deliberately somewhat wordier than if I was just replying
> to the message myself, to try to get my thinking across. So please bear
> with me.
>
> Frankly, I'm never sure where to begin fixing *anything* that's not
> immediately obvious. The first step in something like this is to
> identify key points where things need to happen and may or may not
> actually be happening, and then work out whether we're hitting those
> points, and if not, why not, and if so, why it's doing something
> different there from what it should (which may include setting something
> up differently for a future action, in this case on signal delivery).
>
> > trap 'echo SIGINT; trap - INT; kill -s INT $$; echo woops' INT
> > kill -s INT $$
> >
> > zsh prints 'woops', but shouldn't.
>
> Martijn is presumably saying the trap - INT within the trap should reset
> it so the interrupt stops the rest of the trap being dlievered. So does
> it reset it? Actually, there's some important information below so you
> probably don't need to, but what you'd have to do is trace through to
> see what's happening on the "trap - INT" on the trap by getting the
> shell to stop when it executes the trap command in the signal caught by
> the kill. The trap is set by the bin_trap() handler; zhandler() is
> called if the shell is handling an interrupt, though not if the
> interrupt is set up to kill or suspend the shell or whatever.
>
> One easy and obvious thing to try is to simplify:
>
> trap - INT; kill -S INT $$; echo foo
>
> That doesn't echo "foo"; that's because the INT is delivered
> immedately. The shell doesn't exit if it's interactive, but we do get
> returned immediately to the command line.
>
> In fact, to shortcut the investigation, I think the key point here is to
> note that the trap is executed inside the signal handler (see the other
> recent thread on signal handlers). So we'd expect the "kill -s INT"
> inside the trap to be delivered after the first trap has exited. So
> that's probably why you get "whoops". So is that really a problem?
> You'll have to disucss that with Martijn. Obviously that's not going to
> change fundamentally without a complete rewrite, and this looks to me a
> rather silly experiment anywawy --- it looks to me like it's abusing the
> mechanism to reissue a signal within something designed to handle the
> signal and then expect that to do something within that same handler ---
> but I don't want to have to go on deciding all this by myself, so feel
> free to disagree and discuss further.
>
> pws
>
next prev parent reply other threads:[~2019-12-16 5:25 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-05 7:08 Test release: 5.6.2-test-3 dana
2019-01-05 17:49 ` Peter Stephenson
2019-01-05 18:42 ` dana
2019-01-05 20:58 ` Martijn Dekker
2019-01-05 21:55 ` Daniel Shahaf
2019-01-06 2:37 ` Axel Beckert
2019-01-06 15:12 ` Jun T.
2019-01-06 16:37 ` dana
2019-01-06 16:43 ` Daniel Shahaf
2019-01-06 16:56 ` dana
2019-01-06 21:34 ` Daniel Tameling
2019-01-07 3:25 ` Jun T
2019-01-07 7:02 ` dana
2019-01-21 12:54 ` ETA for zsh 5.7? (was: Test release: 5.6.2-test-3) Axel Beckert
2019-01-21 14:26 ` Peter Stephenson
2019-01-21 19:14 ` Mikael Magnusson
2019-01-21 19:32 ` Mikael Magnusson
2019-01-21 21:56 ` Sebastian Gniazdowski
2019-01-22 9:29 ` Peter Stephenson
2019-01-21 19:32 ` Mikael Magnusson
2019-01-21 23:00 ` Bug with traps and exit Martijn Dekker
2019-11-24 5:54 ` Martijn Dekker
2019-11-25 16:42 ` Sebastian Gniazdowski
2019-12-10 19:23 ` Martijn Dekker
2019-12-11 2:40 ` Daniel Shahaf
2019-12-12 10:14 ` Peter Stephenson
2019-12-13 14:26 ` Martijn Dekker
2019-12-13 14:49 ` Peter Stephenson
2019-12-14 11:28 ` Daniel Shahaf
2019-12-15 18:59 ` Peter Stephenson
2019-12-16 5:24 ` Daniel Shahaf [this message]
2019-12-16 6:37 ` Bart Schaefer
2019-12-17 7:31 ` Daniel Shahaf
2019-12-17 20:29 ` Peter Stephenson
2019-12-18 0:31 ` Daniel Shahaf
2019-12-31 2:03 ` Daniel Shahaf
2019-12-31 13:46 ` Daniel Shahaf
2019-12-16 10:09 ` Peter Stephenson
2019-12-16 5:27 ` The bug from workers/44922 (was: " Daniel Shahaf
2020-01-30 13:49 ` The bug from workers/44922 Martijn Dekker
2020-01-30 14:01 ` Bug with traps and exit Martijn Dekker
2020-01-31 4:29 ` Daniel Shahaf
2022-11-26 3: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=20191216052423.svgnhfkpsxh46a6j@tarpaulin.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=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).