Source: cwidget
Severity: normal
Tags: upstream

For aptitude (and other possible clients) to be able to use signal handlers
effectively (e.g. clean-up after Ctrl-C), cwidget needs to deliver the signal to
them.

At the moment, toplevel::init() (called by aptitude) invokes
install_sighandlers(), sigkilled is the signal handler in all cases, and when
installing the new handlers the old are not saved.

The previous signal handlers should be saved if possible, and after cwidget
handles them (by tearing down the curses interface so the terminal is in usable
state), should pass the signals back to the original signal handler, so they can
do further clean-up that it's considered appropriate.

Documentation about how to implement this:

  
https://www.gnu.org/software/libc/manual/html_node/Basic-Signal-Handling.html#Basic-Signal-Handling

================

    // Cleanly shutdown (eg, restore screen settings if possible)
    //
    // Called on SIGTERM, SIGINT, SIGSEGV, SIGABRT, and SIGQUIT
    //
    // FIXME: revert to the /previous/ handler, not just SIG_DFL?
    static void sigkilled(int sig)
    {
      endwin();

      switch(sig)
        {
        case SIGTERM:
          fprintf(stderr, _("Ouch!  Got SIGTERM, dying..\n"));
          break;
        case SIGSEGV:
          fprintf(stderr, _("Ouch!  Got SIGSEGV, dying..\n"));
          break;
        case SIGABRT:
          fprintf(stderr, _("Ouch!  Got SIGABRT, dying..\n"));
          break;
        case SIGQUIT:
          fprintf(stderr, _("Ouch!  Got SIGQUIT, dying..\n"));
          break;
        }

      signal(sig, SIG_DFL);
      raise(sig);
    }

    [...]

    void install_sighandlers()
    {
      signal(SIGTERM, sigkilled);
      signal(SIGINT, sigkilled);
      signal(SIGSEGV, sigkilled);
      signal(SIGQUIT, sigkilled);
      signal(SIGABRT, sigkilled);
    }


--
Manuel

Reply via email to