Back to index

tetex-bin  3.0
Defines | Typedefs | Functions | Variables
signals.c File Reference
#include "info.h"
#include "signals.h"

Go to the source code of this file.

Defines

#define set_termsig(sig, old)   (void)(*(old) = signal (sig, info_signal_proc))
#define restore_termsig(sig, saved)   (void)signal (sig, *(saved))
#define info_signal_handler   info_signal_proc

Typedefs

typedef RETSIGTYPE(* signal_info )()

Functions

void initialize_info_signal_handler (void)
static RETSIGTYPE info_signal_proc (int sig)
static void redisplay_after_signal (void)
static void reset_info_window_sizes (void)

Variables

static int term_conf_busy = 0
static signal_info old_TSTP
static signal_info old_TTOU
static signal_info old_TTIN
static signal_info old_WINCH
static signal_info old_INT
static signal_info old_USR1
static signal_info old_QUIT

Define Documentation

Definition at line 110 of file signals.c.

#define restore_termsig (   sig,
  saved 
)    (void)signal (sig, *(saved))

Definition at line 109 of file signals.c.

#define set_termsig (   sig,
  old 
)    (void)(*(old) = signal (sig, info_signal_proc))

Definition at line 108 of file signals.c.


Typedef Documentation

typedef RETSIGTYPE(* signal_info)()

Definition at line 107 of file signals.c.


Function Documentation

static RETSIGTYPE info_signal_proc ( int  sig) [static]

Definition at line 180 of file signals.c.

{
  signal_info *old_signal_handler = NULL;

#if !defined (HAVE_SIGACTION)
  /* best effort: first increment this counter and later block signals */
  if (term_conf_busy)
    return;
  term_conf_busy++;
#if defined (HAVE_SIGPROCMASK) || defined (HAVE_SIGSETMASK)
    {
      sigset_t nvar, ovar;
      sigemptyset (&nvar);
      mask_termsig (&nvar);
      sigprocmask (SIG_BLOCK, &nvar, &ovar);
    }
#endif /* HAVE_SIGPROCMASK || HAVE_SIGSETMASK */
#endif /* !HAVE_SIGACTION */
  switch (sig)
    {
#if defined (SIGTSTP)
    case SIGTSTP:
    case SIGTTOU:
    case SIGTTIN:
#endif
#if defined (SIGQUIT)
    case SIGQUIT:
#endif
#if defined (SIGINT)
    case SIGINT:
#endif
      {
#if defined (SIGTSTP)
        if (sig == SIGTSTP)
          old_signal_handler = &old_TSTP;
        if (sig == SIGTTOU)
          old_signal_handler = &old_TTOU;
        if (sig == SIGTTIN)
          old_signal_handler = &old_TTIN;
#endif /* SIGTSTP */
#if defined (SIGQUIT)
        if (sig == SIGQUIT)
          old_signal_handler = &old_QUIT;
#endif /* SIGQUIT */
#if defined (SIGINT)
        if (sig == SIGINT)
          old_signal_handler = &old_INT;
#endif /* SIGINT */

        /* For stop signals, restore the terminal IO, leave the cursor
           at the bottom of the window, and stop us. */
        terminal_goto_xy (0, screenheight - 1);
        terminal_clear_to_eol ();
        fflush (stdout);
        terminal_unprep_terminal ();
       restore_termsig (sig, old_signal_handler);
       UNBLOCK_SIGNAL (sig);
       kill (getpid (), sig);

        /* The program is returning now.  Restore our signal handler,
           turn on terminal handling, redraw the screen, and place the
           cursor where it belongs. */
        terminal_prep_terminal ();
       set_termsig (sig, old_signal_handler);
       /* window size might be changed while sleeping */
       reset_info_window_sizes ();
      }
      break;

#if defined (SIGWINCH) || defined (SIGUSR1)
#ifdef SIGWINCH
    case SIGWINCH:
#endif
#ifdef SIGUSR1
    case SIGUSR1:
#endif
      {
       /* Turn off terminal IO, tell our parent that the window has changed,
          then reinitialize the terminal and rebuild our windows. */
#ifdef SIGWINCH
       if (sig == SIGWINCH)
         old_signal_handler = &old_WINCH;
#endif
#ifdef SIGUSR1
       if (sig == SIGUSR1)
         old_signal_handler = &old_USR1;
#endif
       terminal_goto_xy (0, 0);
       fflush (stdout);
       terminal_unprep_terminal (); /* needless? */
       restore_termsig (sig, old_signal_handler);
       UNBLOCK_SIGNAL (sig);
       kill (getpid (), sig);

       /* After our old signal handler returns... */
       set_termsig (sig, old_signal_handler); /* needless? */
       terminal_prep_terminal ();
       reset_info_window_sizes ();
      }
      break;
#endif /* SIGWINCH || SIGUSR1 */
    }
#if !defined (HAVE_SIGACTION)
  /* at this time it is safer to perform unblock after decrement */
  term_conf_busy--;
#if defined (HAVE_SIGPROCMASK) || defined (HAVE_SIGSETMASK)
    {
      sigset_t nvar, ovar;
      sigemptyset (&nvar);
      mask_termsig (&nvar);
      sigprocmask (SIG_UNBLOCK, &nvar, &ovar);
    }
#endif /* HAVE_SIGPROCMASK || HAVE_SIGSETMASK */
#endif /* !HAVE_SIGACTION */
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 119 of file signals.c.

{
#ifdef SA_NOCLDSTOP
  /* (Based on info from Paul Eggert found in coreutils.)  Don't use
     HAVE_SIGACTION to decide whether to use the sa_handler, sa_flags,
     sa_mask members, as some systems (Solaris 7+) don't define them.  Use
     SA_NOCLDSTOP instead; it's been part of POSIX.1 since day 1 (in 1988).  */
  info_signal_handler.sa_handler = info_signal_proc;
  info_signal_handler.sa_flags = 0;
  mask_termsig (&info_signal_handler.sa_mask);
#endif /* SA_NOCLDSTOP */

#if defined (SIGTSTP)
  set_termsig (SIGTSTP, &old_TSTP);
  set_termsig (SIGTTOU, &old_TTOU);
  set_termsig (SIGTTIN, &old_TTIN);
#endif /* SIGTSTP */

#if defined (SIGWINCH)
  set_termsig (SIGWINCH, &old_WINCH);
#endif

#if defined (SIGQUIT)
  set_termsig (SIGQUIT, &old_QUIT);
#endif

#if defined (SIGINT)
  set_termsig (SIGINT, &old_INT);
#endif

#if defined (SIGUSR1)
  /* Used by DJGPP to simulate SIGTSTP on Ctrl-Z.  */
  set_termsig (SIGUSR1, &old_USR1);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void redisplay_after_signal ( void  ) [static]

Definition at line 156 of file signals.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void reset_info_window_sizes ( void  ) [static]

Definition at line 167 of file signals.c.

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

signal_info old_INT [static]

Definition at line 115 of file signals.c.

Definition at line 116 of file signals.c.

Definition at line 114 of file signals.c.

Definition at line 114 of file signals.c.

Definition at line 114 of file signals.c.

Definition at line 115 of file signals.c.

Definition at line 115 of file signals.c.

int term_conf_busy = 0 [static]

Definition at line 111 of file signals.c.