From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25179 invoked by alias); 11 May 2013 16:03:51 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31392 Received: (qmail 13701 invoked from network); 11 May 2013 16:03:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.210.50 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:content-type:content-transfer-encoding:subject :message-id:date:to:mime-version:x-mailer; bh=ud3Ib6UD2nRNBeCmO9mQ9JgQVWjl3/TDq8SduoE1Vg0=; b=hnrDMRrUDy5pUOC+Yj9IUAaMOiQC2CA9+hibTGV73pqx2Pg+JEZ0QpZu4vlIblSgFU Tns60zAqWvZd8WoGeUiFCWPQPavzSMlYeUAYLukgtiWhlnuKCJbv3o/Q05wPl2AIy885 e2rNSX+2wc866lW9UnnfywHUXOyg3kJTgAm1vT0NlLBbeHNMIIyxFll7Nx1FElXS5yjD t3tghtLezXonL9ZzNLVWkI+D7Vckgo9llVPEKRlrNvaFMcyBG2H9qYXUZ37aQqqB++Dz ktsyLNXc0tCvjjbiJ8E8WPxlaODFujmPUSFh15/Go3n9b0sJvs0QSrMWe6+icirkFQo/ javQ== X-Received: by 10.66.11.164 with SMTP id r4mr8297769pab.221.1368288197558; Sat, 11 May 2013 09:03:17 -0700 (PDT) From: Jeremy Mates Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: A tail of two situations Message-Id: <01B63421-5BF1-4160-ABEA-FA799C10BF04@gmail.com> Date: Sat, 11 May 2013 09:03:25 -0700 To: zsh-workers@zsh.org Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) X-Mailer: Apple Mail (2.1503) 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.