NeoMutt  2021-02-05-666-ge300cd
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 "mutt_attach.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 
126 #ifdef USE_SLANG_CURSES
127 
131 static int mutt_intr_hook(void)
132 {
133  return -1;
134 }
135 #endif /* USE_SLANG_CURSES */
136 
141 {
143 
144 #ifdef USE_SLANG_CURSES
145  /* This bit of code is required because of the implementation of
146  * SLcurses_wgetch(). If a signal is received (like SIGWINCH) when we
147  * are in blocking mode, SLsys_getkey() will not return an error unless
148  * a handler function is defined and it returns -1. This is needed so
149  * that if the user resizes the screen while at a prompt, it will just
150  * abort and go back to the main-menu. */
151  SLang_getkey_intr_hook = mutt_intr_hook;
152 #endif
153 }
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
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
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: mutt_globals.h:67
void mutt_unlink_temp_attachments(void)
Delete all temporary attachments.
Definition: mutt_attach.c:1275
static void curses_exit_handler(int sig)
Notify the user and shutdown gracefully - Implements sig_handler_t.
Definition: mutt_signal.c:94
static int IsEndwin
Definition: mutt_signal.c:45
Container for Accounts, Notifications.
Definition: neomutt.h:36
Convenience wrapper for the config headers.
void mutt_signal_init(void)
Initialise the signal handling.
Definition: mutt_signal.c:140
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:71
Display a normal cursor.
Definition: mutt_curses.h:81
Convenience wrapper for the core headers.
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
Prototypes for many functions.
Handling of email attachments.
Restore the previous cursor state.
Definition: mutt_curses.h:79
Convenience wrapper for the debug headers.
void dump_graphviz(const char *title, struct Context *ctx)
Definition: graphviz.c:945
void show_backtrace(void)
Log the program&#39;s call stack.
Definition: backtrace.c:39
Hundreds of global variables to back the user variables.
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Convenience wrapper for the library headers.
static void curses_segv_handler(int sig)
Catch a segfault and print a backtrace - Implements sig_handler_t.
Definition: mutt_signal.c:106
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: mutt_globals.h:68