zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Cc: Patrick Palka <patrick@parcs.ath.cx>
Subject: Re: TRAPINT function set by parent shell causes subshell to misbehave
Date: Fri, 26 Jun 2015 14:08:51 -0700	[thread overview]
Message-ID: <150626140851.ZM21683@torch.brasslantern.com> (raw)
In-Reply-To: <CA+C-WL8BJ5GK25kCxvH5c=CfZCTapu0aWARvuiQPEGn4QpnigA@mail.gmail.com>

On Jun 26,  3:21pm, Patrick Palka wrote:
}
} So when a TRAPINT function is defined in the parent shell and not
} redefined in the subshell, then the subshell decides to exit when
} SIGINT is sent to it -- at least when the 'less' command is run.

In part this is because "less" installs its own trap for that signal,
but there may be a bug in the handling of the TRAPS_ASYNC option.

(remarks below refer to zsh-5.0.8, behavior may differ in older versions)

In the first case, less and the subshell both receive the signal but
both ignore it.  In the second case they both receive it but only less
ignores it.  In the third case they both receive it, less ignores it,
and the subshell waits for less to exit before processing it.

Thus in the second case where you think both the subshell and less have
been killed, you are actually not quite correct -- the subshell was
interrupted, but less exited on its own as a side-effect.

You can see what's going on if you define

    zmodload zsh/system
    TRAPINT() { print $$ $sysparams[pid] }

In the second case, the parent shell receives the signal and kills the
subshell.  In the third case, the subshell receives the signal because
it has redefined the trap ($$ and $sysparams[pid] differ in the trap).

If instead you use the "trap" command instead of defining the function,
the parent shell also waits before processing the signal.  I'm not sure
if this is as intended or not; changing TRAPS_ASYNC makes the second
and third cases both handle the trap immediately, no matter which way
of defining the trap was used.


      reply	other threads:[~2015-06-26 21:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26 19:21 Patrick Palka
2015-06-26 21:08 ` 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=150626140851.ZM21683@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=patrick@parcs.ath.cx \
    --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).