NeoMutt  2021-10-29-33-g41675a
Teaching an old dog new tricks
DOXYGEN
mutt_signal.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stddef.h>
31 #include <errno.h>
32 #include <signal.h>
33 #include <stdbool.h>
34 #include "mutt/lib.h"
35 #include "config/lib.h"
36 #include "core/lib.h"
37 #include "gui/lib.h"
38 #include "attach/lib.h"
39 #include "mutt_globals.h"
40 #include "protos.h" // IWYU pragma: keep
41 #ifdef USE_DEBUG_GRAPHVIZ
42 #include "debug/lib.h"
43 #endif
44 
45 static int IsEndwin = 0;
46 
51 static void curses_signal_handler(int sig)
52 {
53  int save_errno = errno;
54 
55  switch (sig)
56  {
57  case SIGTSTP: /* user requested a suspend */
58  {
59  const bool c_suspend = cs_subset_bool(NeoMutt->sub, "suspend");
60  if (!c_suspend)
61  break;
62  IsEndwin = isendwin();
64  if (!IsEndwin)
65  endwin();
66  kill(0, SIGSTOP);
67  }
68  /* fallthrough */
69 
70  case SIGCONT:
71  if (!IsEndwin)
72  refresh();
74  /* We don't receive SIGWINCH when suspended; however, no harm is done by
75  * just assuming we received one, and triggering the 'resize' anyway. */
76  SigWinch = true;
77  break;
78 
79  case SIGWINCH:
80  SigWinch = true;
81  break;
82 
83  case SIGINT:
84  SigInt = true;
85  break;
86  }
87  errno = save_errno;
88 }
89 
94 static void curses_exit_handler(int sig)
95 {
97  endwin(); /* just to be safe */
99  mutt_sig_exit_handler(sig); /* DOES NOT RETURN */
100 }
101 
106 static void curses_segv_handler(int sig)
107 {
109  endwin(); /* just to be safe */
110 #ifdef HAVE_LIBUNWIND
111  show_backtrace();
112 #endif
113 #ifdef USE_DEBUG_GRAPHVIZ
114  dump_graphviz("segfault", NULL);
115 #endif
116 
117  struct sigaction act;
118  sigemptyset(&act.sa_mask);
119  act.sa_flags = 0;
120  act.sa_handler = SIG_DFL;
121  sigaction(sig, &act, NULL);
122  // Re-raise the signal to give outside handlers a chance to deal with it
123  raise(sig);
124 }
125 
130 {
132 }
GUI display the mailboxes in a side panel.
void show_backtrace(void)
Log the program's call stack.
Definition: backtrace.c:39
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
Convenience wrapper for the debug headers.
void dump_graphviz(const char *title, struct Context *ctx)
Definition: graphviz.c:962
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:51
static void curses_segv_handler(int sig)
Catch a segfault and print a backtrace - Implements sig_handler_t -.
Definition: mutt_signal.c:106
static void curses_exit_handler(int sig)
Notify the user and shutdown gracefully - Implements sig_handler_t -.
Definition: mutt_signal.c:94
Convenience wrapper for the gui headers.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Convenience wrapper for the library headers.
void mutt_unlink_temp_attachments(void)
Delete all temporary attachments.
Definition: mutt_attach.c:1289
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:63
@ MUTT_CURSOR_RESTORE_LAST
Restore the previous cursor state.
Definition: mutt_curses.h:53
@ MUTT_CURSOR_VISIBLE
Display a normal cursor.
Definition: mutt_curses.h:55
Hundreds of global variables to back the user variables.
SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: mutt_globals.h:74
SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: mutt_globals.h:73
static int IsEndwin
Definition: mutt_signal.c:45
void mutt_signal_init(void)
Initialise the signal handling.
Definition: mutt_signal.c:129
Prototypes for many functions.
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
void mutt_sig_exit_handler(int sig)
Notify the user and shutdown gracefully.
Definition: signal.c:65
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39