zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Possible signal handling issues
Date: Sat, 28 Dec 2013 15:02:34 -0800	[thread overview]
Message-ID: <131228150234.ZM27671@torch.brasslantern.com> (raw)

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.

I'm uncertain whether this next one is actually a bug.  This is from Chris
Johnson's question on zsh-users:

--- snip ---
sleep 10000 &
longpid=$!

sleepkill() {
  sleep 20
  print "timed out"
  kill $longpid
}

sleepkill &
sleeppid=$!

TRAPINT() {
  set -x
  kill $longpid
  #kill $sleeppid      # test 1
  #kill -- -$sleeppid  # test 2
  #kill -HUP -$$       # test 3
}
sleep 30
-- snip --

I avoided using "wait" as the last line there to show it's not related to
the previous bug.  If we run that script and then interrupt with ctrl+c,
the entire sleepkill function is left running in the background.  That's
probably correct because the monitor option is off in scripts so the hup
option does not apply.

Uncomment test 1.  Now the subshell started for sleepkill is terminated,
but "sleep 20" is left running.  This seems very odd to me, because that
sleep was never backgrounded relative to the sleepkill function.  Remove
test 1 and uncomment test 2 and you get a "no such process" error, which
indicates that sleepkill is not a "process group leader" so none of its
children receive its signals.  Uncomment test 3 which signals the whole
process group of the original script, and everything gets killed off.

Should the subshell be propagating that signal in the first test?


             reply	other threads:[~2013-12-28 23:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-28 23:02 Bart Schaefer [this message]
2014-01-02 21:55 ` Peter Stephenson
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=131228150234.ZM27671@torch.brasslantern.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).