NeoMutt  2019-12-07-60-g0cfa53
Teaching an old dog new tricks
DOXYGEN
mutt_signal.c File Reference

Signal handling. More...

#include "config.h"
#include <stddef.h>
#include <errno.h>
#include <signal.h>
#include "mutt/mutt.h"
#include "gui/lib.h"
#include "globals.h"
#include "mutt_attach.h"
#include "protos.h"
+ Include dependency graph for mutt_signal.c:

Go to the source code of this file.

Functions

static void curses_signal_handler (int sig)
 Catch signals and relay the info to the main program. More...
 
static void curses_exit_handler (int sig)
 Notify the user and shutdown gracefully. More...
 
static void curses_segv_handler (int sig)
 Catch a segfault and print a backtrace. More...
 
void mutt_signal_init (void)
 Initialise the signal handling. More...
 

Variables

static int IsEndwin = 0
 

Detailed Description

Signal handling.

Authors
  • Michael R. Elkins

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file mutt_signal.c.

Function Documentation

◆ curses_signal_handler()

static void curses_signal_handler ( int  sig)
static

Catch signals and relay the info to the main program.

Parameters
sigSignal number, e.g. SIGINT

Definition at line 48 of file mutt_signal.c.

49 {
50  int save_errno = errno;
51 
52  switch (sig)
53  {
54  case SIGTSTP: /* user requested a suspend */
55  if (!C_Suspend)
56  break;
57  IsEndwin = isendwin();
59  if (!IsEndwin)
60  endwin();
61  kill(0, SIGSTOP);
62  /* fallthrough */
63 
64  case SIGCONT:
65  if (!IsEndwin)
66  refresh();
68  /* We don't receive SIGWINCH when suspended; however, no harm is done by
69  * just assuming we received one, and triggering the 'resize' anyway. */
70  SigWinch = 1;
71  break;
72 
73  case SIGWINCH:
74  SigWinch = 1;
75  break;
76 
77  case SIGINT:
78  SigInt = 1;
79  break;
80  }
81  errno = save_errno;
82 }
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: globals.h:79
static int IsEndwin
Definition: mutt_signal.c:42
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:76
Display a normal cursor.
Definition: mutt_curses.h:82
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.h:80
Restore the previous cursor state.
Definition: mutt_curses.h:80
WHERE bool C_Suspend
Config: Allow the user to suspend NeoMutt using &#39;^Z&#39;.
Definition: globals.h:256
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ curses_exit_handler()

static void curses_exit_handler ( int  sig)
static

Notify the user and shutdown gracefully.

Parameters
sigSignal number, e.g. SIGTERM

Definition at line 88 of file mutt_signal.c.

89 {
91  endwin(); /* just to be safe */
93  mutt_sig_exit_handler(sig); /* DOES NOT RETURN */
94 }
void mutt_unlink_temp_attachments(void)
Delete all temporary attachments.
Definition: mutt_attach.c:1196
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:76
Display a normal cursor.
Definition: mutt_curses.h:82
void mutt_sig_exit_handler(int sig)
Notify the user and shutdown gracefully.
Definition: signal.c:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ curses_segv_handler()

static void curses_segv_handler ( int  sig)
static

Catch a segfault and print a backtrace.

Parameters
sigSignal number, e.g. SIGSEGV

Definition at line 100 of file mutt_signal.c.

101 {
103  endwin(); /* just to be safe */
104 #ifdef HAVE_LIBUNWIND
105  show_backtrace();
106 #endif
107 
108  struct sigaction act;
109  sigemptyset(&act.sa_mask);
110  act.sa_flags = 0;
111  act.sa_handler = SIG_DFL;
112  sigaction(sig, &act, NULL);
113  // Re-raise the signal to give outside handlers a chance to deal with it
114  raise(sig);
115 }
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:76
Display a normal cursor.
Definition: mutt_curses.h:82
void show_backtrace(void)
Log the program&#39;s call stack.
Definition: backtrace.c:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_signal_init()

void mutt_signal_init ( void  )

Initialise the signal handling.

Definition at line 131 of file mutt_signal.c.

132 {
134 
135 #ifdef USE_SLANG_CURSES
136  /* This bit of code is required because of the implementation of
137  * SLcurses_wgetch(). If a signal is received (like SIGWINCH) when we
138  * are in blocking mode, SLsys_getkey() will not return an error unless
139  * a handler function is defined and it returns -1. This is needed so
140  * that if the user resizes the screen while at a prompt, it will just
141  * abort and go back to the main-menu. */
142  SLang_getkey_intr_hook = mutt_intr_hook;
143 #endif
144 }
static void curses_signal_handler(int sig)
Catch signals and relay the info to the main program.
Definition: mutt_signal.c:48
static void curses_exit_handler(int sig)
Notify the user and shutdown gracefully.
Definition: mutt_signal.c:88
void mutt_sig_init(sig_handler_t sig_fn, sig_handler_t exit_fn, sig_handler_t segv_fn)
Initialise the signal handling.
Definition: signal.c:88
static void curses_segv_handler(int sig)
Catch a segfault and print a backtrace.
Definition: mutt_signal.c:100
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ IsEndwin

int IsEndwin = 0
static

Definition at line 42 of file mutt_signal.c.