zsh-workers
 help / color / mirror / code / Atom feed
From: Philippe Troin <phil@fifi.org>
To: zsh-workers@sunsite.dk
Subject: Inconsistent signal handling?
Date: 25 Oct 2002 20:22:16 -0700	[thread overview]
Message-ID: <877kg5c2af.fsf@ceramic.fifi.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 2508 bytes --]

In init.c, init_signals() says:

    void
    init_signals(void)
    {
        sigchld_mask = signal_mask(SIGCHLD);

        intr();

    #ifndef QDEBUG
        signal_ignore(SIGQUIT);
    #endif

        install_handler(SIGHUP);
        install_handler(SIGCHLD);
    #ifdef SIGWINCH
        install_handler(SIGWINCH);
    #endif
        if (interact) {
            install_handler(SIGALRM);
[1]         signal_ignore(SIGTERM);
        }
        if (jobbing) {
[2]         long ttypgrp;
[2]
[2]         while ((ttypgrp = gettygrp()) != -1 && ttypgrp != mypgrp)
[2]             kill(0, SIGTTIN);
[2]         if (ttypgrp == -1) {
[2]             opts[MONITOR] = 0;
[2]         } else {
[2]             signal_ignore(SIGTTOU);
[2]             signal_ignore(SIGTSTP);
[2]             signal_ignore(SIGTTIN);
[2]             attachtty(mypgrp);
[2]         }
        }
[3]     if (islogin) {
[4]         signal_setmask(signal_mask(0));
        } else if (interact) {
            sigset_t set;

            sigemptyset(&set);
            sigaddset(&set, SIGINT);
            sigaddset(&set, SIGQUIT);
            signal_unblock(set);
        }
    }

My remarks:

 [1] Why do we ignore SIGTERM on interactive sessions? That sounds
     like a bad idea to me.

 [2] See my previous mail <87bs5hc31h.fsf@ceramic.fifi.org>

 [3] Why do we only clean-up the signal mask on login shells? It
     should happen on interactive shells (there can be login
     non-interactive shells, eg. for X11 startup).

 [4] This is not enough to clean-up all inherited signal
     properties. If some signals have been ignored (with
     signal(SIG_IGN)) before zsh was exec()ed, then they are still
     ignored by zsh. exec*() only resets the disposition of signals
     which have a signal handler to SIG_DFL, but leaves SIG_IGNored
     signals as is (this is a POSIX requirement).

I'd suggest changing init_signals to:

void
init_signals(void)
{
    if (interact) {
        int i;
        signal_setmask(signal_mask(0));
        for (i=0; i<NSIG; ++i)
            signal_default(i);
    }
    sigchld_mask = signal_mask(SIGCHLD);

    intr();

#ifndef QDEBUG
    signal_ignore(SIGQUIT);
#endif

    install_handler(SIGHUP);
    install_handler(SIGCHLD);
#ifdef SIGWINCH
    install_handler(SIGWINCH);
#endif
    if (interact) {
        install_handler(SIGALRM);
    }
    if (jobbing) {
        signal_ignore(SIGTTOU);
        signal_ignore(SIGTSTP);
        signal_ignore(SIGTTIN);
    }
}

Patch against 4.0.6 attached.

Phil.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: zsh-4.0.6-signals.patch --]
[-- Type: text/x-patch, Size: 1304 bytes --]

diff -rc zsh-4.0.6.orig/Src/init.c zsh-4.0.6/Src/init.c
*** zsh-4.0.6.orig/Src/init.c	Fri Oct 25 19:43:15 2002
--- zsh-4.0.6/Src/init.c	Fri Oct 25 20:19:02 2002
***************
*** 842,847 ****
--- 842,853 ----
  void
  init_signals(void)
  {
+     if (interact) {
+ 	int i;
+ 	signal_setmask(signal_mask(0));
+ 	for (i=0; i<NSIG; ++i)
+ 	    signal_default(i);
+     }
      sigchld_mask = signal_mask(SIGCHLD);
  
      intr();
***************
*** 857,887 ****
  #endif
      if (interact) {
  	install_handler(SIGALRM);
- 	signal_ignore(SIGTERM);
      }
      if (jobbing) {
! 	long ttypgrp;
! 
! 	while ((ttypgrp = gettygrp()) != -1 && ttypgrp != mypgrp)
! 	    kill(0, SIGTTIN);
! 	if (ttypgrp == -1) {
! 	    opts[MONITOR] = 0;
! 	} else {
! 	    signal_ignore(SIGTTOU);
! 	    signal_ignore(SIGTSTP);
! 	    signal_ignore(SIGTTIN);
! 	    attachtty(mypgrp);
! 	}
!     }
!     if (islogin) {
! 	signal_setmask(signal_mask(0));
!     } else if (interact) {
! 	sigset_t set;
! 
! 	sigemptyset(&set);
! 	sigaddset(&set, SIGINT);
! 	sigaddset(&set, SIGQUIT);
! 	signal_unblock(set);
      }
  }
  
--- 863,873 ----
  #endif
      if (interact) {
  	install_handler(SIGALRM);
      }
      if (jobbing) {
! 	signal_ignore(SIGTTOU);
! 	signal_ignore(SIGTSTP);
! 	signal_ignore(SIGTTIN);
      }
  }
  

             reply	other threads:[~2002-10-26  3:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-26  3:22 Philippe Troin [this message]
2002-11-04 14:04 ` Peter Stephenson
2002-11-04 19:22   ` Philippe Troin
2002-11-07 10:58     ` Peter Stephenson
2002-11-07 21:05       ` Philippe Troin
2002-11-08 10:44         ` Peter Stephenson
2002-11-09  1:14           ` Philippe Troin
2002-11-12 21:57             ` Zefram
2002-11-12 23:29               ` Philippe Troin

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=877kg5c2af.fsf@ceramic.fifi.org \
    --to=phil@fifi.org \
    --cc=zsh-workers@sunsite.dk \
    /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).