From: Jeremy Mates <jeremy.mates@gmail.com>
To: zsh-workers@zsh.org
Subject: A tail of two situations
Date: Sat, 11 May 2013 09:03:25 -0700 [thread overview]
Message-ID: <01B63421-5BF1-4160-ABEA-FA799C10BF04@gmail.com> (raw)
If MONITOR is set in ZSH, and control+c issued, the subsequent command
*is not* run:
% tail -n0 -f /etc/passwd; echo foo
^C
%
However! If tail is modified to handle SIGINT, and quits via errx(3)
or the like:
void polonius_polka(int sig)
{
errx(1, "oh I am slain"); // 128+sig does not replicate "err by sig"
}
the subsequent command *is* run:
% tail -n0 -f /etc/passwd; echo foo
^Ctail: oh I am slain
foo
%
This seems inconsistent, as the behavior deep within ZSH (with MONITOR
set) depends on how(if) the program handles the ^C. Consistency in ZSH
demands either `unsetopt MONITOR` (subsequent code never run), or using
a subshell and trapping INT via a "function trap" (subsequent code run):
% ( TRAPINT(){}; tail -n0 -f /etc/passwd ); echo foo
^Cfoo
%
(But not the "list trap" `trap '' INT`, as that causes ZSH to ignore the
SIGINT, and pass that ignore down to tail, unless disabling control+c
is for some reason desired.)
Spelunking Src/jobs.c and Src/signals.c reveals that in either case
(`tail` having a signal handler or not), ZSH receives a SIGCHLD, and
that the only apparent difference is the contents of the "status" int
populated by the wait(2) call, which eventually reaches the
/* When MONITOR is set, the foreground process runs in a different *
* process group from the shell, so the shell will not receive *
* terminal signals, therefore we pretend that the shell got *
* the signal too. */
if (inforeground == 2 && isset(MONITOR) && WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
block of code in Src/jobs.c, and then for the tail-with-no-signal-
handler case the code sets `breaks = loops; errflag = 1`, wanders into
check_cursh_sig(), which does nothing in this case, and then the code
returns to who knows where. Something in that subsequent code then does
not run the `; echo foo` code. However, I do not know where that code
is, and do not know whether changing it would cause any other
ramifications. It might be nice to have consistent behavior, though
there is a workaround of either unsetting MONITOR, or using a
subshell/TRAPINT function.
next reply other threads:[~2013-05-11 16:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-11 16:03 Jeremy Mates [this message]
2013-05-11 22:40 ` 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=01B63421-5BF1-4160-ABEA-FA799C10BF04@gmail.com \
--to=jeremy.mates@gmail.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).