NeoMutt  2020-08-21-74-g346364
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/lib.h"
#include "gui/lib.h"
#include "debug/lib.h"
#include "mutt_attach.h"
#include "mutt_globals.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 - Implements sig_handler_t. More...
 
static void curses_exit_handler (int sig)
 Notify the user and shutdown gracefully - Implements sig_handler_t. More...
 
static void curses_segv_handler (int sig)
 Catch a segfault and print a backtrace - Implements sig_handler_t. 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 - Implements sig_handler_t.

Parameters
sigSignal number, e.g. SIGINT

Definition at line 46 of file mutt_signal.c.

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

Parameters
sigSignal number, e.g. SIGTERM

Definition at line 86 of file mutt_signal.c.

87 {
89  endwin(); /* just to be safe */
91  mutt_sig_exit_handler(sig); /* DOES NOT RETURN */
92 }
void mutt_unlink_temp_attachments(void)
Delete all temporary attachments.
Definition: mutt_attach.c:1258
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:78
Display a normal cursor.
Definition: mutt_curses.h:81
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 - Implements sig_handler_t.

Parameters
sigSignal number, e.g. SIGSEGV

Definition at line 98 of file mutt_signal.c.

99 {
101  endwin(); /* just to be safe */
102 #ifdef HAVE_LIBUNWIND
103  show_backtrace();
104 #endif
105 #ifdef USE_DEBUG_GRAPHVIZ
106  dump_graphviz("segfault");
107 #endif
108 
109  struct sigaction act;
110  sigemptyset(&act.sa_mask);
111  act.sa_flags = 0;
112  act.sa_handler = SIG_DFL;
113  sigaction(sig, &act, NULL);
114  // Re-raise the signal to give outside handlers a chance to deal with it
115  raise(sig);
116 }
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:78
Display a normal cursor.
Definition: mutt_curses.h:81
void show_backtrace(void)
Log the program&#39;s call stack.
Definition: backtrace.c:39
void dump_graphviz(const char *title)
Definition: graphviz.c:930
+ 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 132 of file mutt_signal.c.

133 {
135 
136 #ifdef USE_SLANG_CURSES
137  /* This bit of code is required because of the implementation of
138  * SLcurses_wgetch(). If a signal is received (like SIGWINCH) when we
139  * are in blocking mode, SLsys_getkey() will not return an error unless
140  * a handler function is defined and it returns -1. This is needed so
141  * that if the user resizes the screen while at a prompt, it will just
142  * abort and go back to the main-menu. */
143  SLang_getkey_intr_hook = mutt_intr_hook;
144 #endif
145 }
static void curses_signal_handler(int sig)
Catch signals and relay the info to the main program - Implements sig_handler_t.
Definition: mutt_signal.c:46
static void curses_exit_handler(int sig)
Notify the user and shutdown gracefully - Implements sig_handler_t.
Definition: mutt_signal.c:86
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 - Implements sig_handler_t.
Definition: mutt_signal.c:98
+ 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 40 of file mutt_signal.c.