NeoMutt  2021-02-05-89-gabe350
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 "mutt/lib.h"
34 #include "gui/lib.h"
35 #include "debug/lib.h"
36 #include "mutt_attach.h"
37 #include "mutt_globals.h"
38 #include "protos.h" // IWYU pragma: keep
39 
40 static int IsEndwin = 0;
41 
46 static void curses_signal_handler(int sig)
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 }
81 
86 static void curses_exit_handler(int sig)
87 {
89  endwin(); /* just to be safe */
91  mutt_sig_exit_handler(sig); /* DOES NOT RETURN */
92 }
93 
98 static void curses_segv_handler(int sig)
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", NULL);
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 }
117 
118 #ifdef USE_SLANG_CURSES
119 
123 static int mutt_intr_hook(void)
124 {
125  return -1;
126 }
127 #endif /* USE_SLANG_CURSES */
128 
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 }
mutt_curses_set_cursor
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:78
dump_graphviz
void dump_graphviz(const char *title, struct Context *ctx)
Definition: graphviz.c:937
SigInt
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: mutt_globals.h:74
curses_segv_handler
static void curses_segv_handler(int sig)
Catch a segfault and print a backtrace - Implements sig_handler_t.
Definition: mutt_signal.c:98
SigWinch
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: mutt_globals.h:75
curses_exit_handler
static void curses_exit_handler(int sig)
Notify the user and shutdown gracefully - Implements sig_handler_t.
Definition: mutt_signal.c:86
IsEndwin
static int IsEndwin
Definition: mutt_signal.c:40
mutt_globals.h
lib.h
MUTT_CURSOR_RESTORE_LAST
@ MUTT_CURSOR_RESTORE_LAST
Restore the previous cursor state.
Definition: mutt_curses.h:79
C_Suspend
WHERE bool C_Suspend
Config: Allow the user to suspend NeoMutt using '^Z'.
Definition: mutt_globals.h:165
protos.h
lib.h
mutt_sig_exit_handler
void mutt_sig_exit_handler(int sig)
Notify the user and shutdown gracefully.
Definition: signal.c:65
mutt_sig_init
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
mutt_signal_init
void mutt_signal_init(void)
Initialise the signal handling.
Definition: mutt_signal.c:132
curses_signal_handler
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
mutt_unlink_temp_attachments
void mutt_unlink_temp_attachments(void)
Delete all temporary attachments.
Definition: mutt_attach.c:1266
show_backtrace
void show_backtrace(void)
Log the program's call stack.
Definition: backtrace.c:39
MUTT_CURSOR_VISIBLE
@ MUTT_CURSOR_VISIBLE
Display a normal cursor.
Definition: mutt_curses.h:81
lib.h
mutt_attach.h