zsh-workers
 help / color / mirror / code / Atom feed
* Inconsistent signal handling?
@ 2002-10-26  3:22 Philippe Troin
  2002-11-04 14:04 ` Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Philippe Troin @ 2002-10-26  3:22 UTC (permalink / raw)
  To: zsh-workers

[-- 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);
      }
  }
  

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-11-12 23:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-26  3:22 Inconsistent signal handling? Philippe Troin
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

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).