Back to index

tetex-bin  3.0
Defines | Functions
lib_tstp.c File Reference
#include <curses.priv.h>
#include <SigAction.h>

Go to the source code of this file.

Defines

#define USE_SIGTSTP   0

Functions

static void cleanup (int sig)
static int CatchIfDefault (int sig, RETSIGTYPE(*handler)(int))
 _nc_signal_handler (bool enable)

Define Documentation

#define USE_SIGTSTP   0

Definition at line 54 of file lib_tstp.c.


Function Documentation

_nc_signal_handler ( bool  enable)

Definition at line 356 of file lib_tstp.c.

{
    static bool initialized = FALSE;

    T((T_CALLED("_nc_signal_handler(%d)"), enable));
#if USE_SIGTSTP                    /* Xenix 2.x doesn't have SIGTSTP, for example */
    {
       static bool ignore_tstp = FALSE;

       if (!ignore_tstp) {
           static sigaction_t act, oact;

           if (!enable) {
              act.sa_handler = SIG_IGN;
              sigaction(SIGTSTP, &act, &oact);
           } else if (act.sa_handler != SIG_DFL) {
              sigaction(SIGTSTP, &oact, NULL);
           } else if (sigaction(SIGTSTP, NULL, &oact) == 0
                     && (oact.sa_handler == SIG_DFL)) {
              sigemptyset(&act.sa_mask);
#ifdef SA_RESTART
              act.sa_flags |= SA_RESTART;
#endif /* SA_RESTART */
              act.sa_handler = tstp;
              (void) sigaction(SIGTSTP, &act, NULL);
           } else {
              ignore_tstp = TRUE;
           }
       }
    }
#endif /* !USE_SIGTSTP */

    if (!initialized) {
       if (enable) {
           CatchIfDefault(SIGINT, cleanup);
           CatchIfDefault(SIGTERM, cleanup);
#if USE_SIGWINCH
           CatchIfDefault(SIGWINCH, sigwinch);
#endif
           initialized = TRUE;
       }
    }
    returnVoid;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int CatchIfDefault ( int  sig,
RETSIGTYPE(*)(int handler 
) [static]

Definition at line 293 of file lib_tstp.c.

{
    int result;
#if HAVE_SIGACTION || HAVE_SIGVEC
    sigaction_t old_act;
    sigaction_t new_act;

    memset(&new_act, 0, sizeof(new_act));
    sigemptyset(&new_act.sa_mask);
#ifdef SA_RESTART
#ifdef SIGWINCH
    if (sig != SIGWINCH)
#endif
       new_act.sa_flags |= SA_RESTART;
#endif /* SA_RESTART */
    new_act.sa_handler = handler;

    if (sigaction(sig, NULL, &old_act) == 0
       && (old_act.sa_handler == SIG_DFL
           || old_act.sa_handler == handler
#if USE_SIGWINCH
           || (sig == SIGWINCH && old_act.sa_handler == SIG_IGN)
#endif
       )) {
       (void) sigaction(sig, &new_act, NULL);
       result = TRUE;
    } else {
       result = FALSE;
    }
#else /* !HAVE_SIGACTION */
    RETSIGTYPE (*ohandler) (int);

    ohandler = signal(sig, SIG_IGN);
    if (ohandler == SIG_DFL
       || ohandler == handler
#if USE_SIGWINCH
       || (sig == SIGWINCH && ohandler == SIG_IGN)
#endif
       ) {
       signal(sig, handler);
       result = TRUE;
    } else {
       signal(sig, ohandler);
       result = FALSE;
    }
#endif
    T(("CatchIfDefault - will %scatch %s",
       result ? "" : "not ", signal_name(sig)));
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void cleanup ( int  sig) [static]

Definition at line 235 of file lib_tstp.c.

{
    static int nested;

    /*
     * Actually, doing any sort of I/O from within an signal handler is
     * "unsafe".  But we'll _try_ to clean up the screen and terminal
     * settings on the way out.
     */
    if (!nested++
       && (sig == SIGINT
           || sig == SIGQUIT)) {
#if HAVE_SIGACTION || HAVE_SIGVEC
       sigaction_t act;
       sigemptyset(&act.sa_mask);
       act.sa_flags = 0;
       act.sa_handler = SIG_IGN;
       if (sigaction(sig, &act, NULL) == 0)
#else
       if (signal(sig, SIG_IGN) != SIG_ERR)
#endif
       {
           SCREEN *scan = _nc_screen_chain;
           while (scan) {
              if (SP != 0
                  && SP->_ofp != 0
                  && isatty(fileno(SP->_ofp))) {
                  SP->_cleanup = TRUE;
                  SP->_outch = _nc_outch;
              }
              set_term(scan);
              endwin();
              if (SP)
                  SP->_endwin = FALSE;    /* in case we have an atexit! */
              scan = scan->_next_screen;
           }
       }
    }
    exit(EXIT_FAILURE);
}

Here is the call graph for this function:

Here is the caller graph for this function: