NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mutt_signal.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <errno.h>
31#include <signal.h>
32#include <stdbool.h>
33#include <stddef.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 "protos.h"
40#if defined(USE_DEBUG_GRAPHVIZ) || defined(USE_DEBUG_BACKTRACE)
41#include "debug/lib.h"
42#endif
43
45static int IsEndwin = 0;
46
51static void curses_signal_handler(int sig)
52{
53 int save_errno = errno;
54 enum MuttCursorState old_cursor = MUTT_CURSOR_VISIBLE;
55
56 switch (sig)
57 {
58 case SIGTSTP: /* user requested a suspend */
59 {
60 const bool c_suspend = cs_subset_bool(NeoMutt->sub, "suspend");
61 if (!c_suspend)
62 break;
63 IsEndwin = isendwin();
65 if (!IsEndwin)
66 endwin();
67 kill(0, SIGSTOP);
68 }
70
71 case SIGCONT:
72 if (!IsEndwin)
73 refresh();
74 mutt_curses_set_cursor(old_cursor);
75 /* We don't receive SIGWINCH when suspended; however, no harm is done by
76 * just assuming we received one, and triggering the 'resize' anyway. */
77 SigWinch = true;
78 break;
79
80 case SIGWINCH:
81 SigWinch = true;
82 break;
83
84 case SIGINT:
85 SigInt = true;
86 break;
87 }
88 errno = save_errno;
89}
90
95static void curses_exit_handler(int sig)
96{
98 endwin(); /* just to be safe */
100 mutt_sig_exit_handler(sig); /* DOES NOT RETURN */
101}
102
107static void curses_segv_handler(int sig)
108{
110 endwin(); /* just to be safe */
111#ifdef USE_DEBUG_BACKTRACE
113#endif
114#ifdef USE_DEBUG_GRAPHVIZ
115 dump_graphviz("segfault", NULL);
116#endif
117
118 struct sigaction act = { 0 };
119 sigemptyset(&act.sa_mask);
120 act.sa_flags = 0;
121 act.sa_handler = SIG_DFL;
122 sigaction(sig, &act, NULL);
123 // Re-raise the signal to give outside handlers a chance to deal with it
124 raise(sig);
125}
126
131{
133}
GUI display the mailboxes in a side panel.
void show_backtrace(void)
Log the program's call stack.
Definition: backtrace.c:39
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
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 MailboxView *mv)
Definition: graphviz.c:897
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:107
static void curses_exit_handler(int sig)
Notify the user and shutdown gracefully - Implements sig_handler_t -.
Definition: mutt_signal.c:95
Convenience wrapper for the gui headers.
Convenience wrapper for the library headers.
#define FALLTHROUGH
Definition: lib.h:111
void mutt_temp_attachments_cleanup(void)
Delete all temporary attachments.
Definition: mutt_attach.c:1309
enum MuttCursorState mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:94
MuttCursorState
Cursor states for mutt_curses_set_cursor()
Definition: mutt_curses.h:64
@ MUTT_CURSOR_VISIBLE
Display a normal cursor.
Definition: mutt_curses.h:66
static int IsEndwin
Ncurses function isendwin() has been called.
Definition: mutt_signal.c:45
void mutt_signal_init(void)
Initialise the signal handling.
Definition: mutt_signal.c:130
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:150
volatile sig_atomic_t SigWinch
true after SIGWINCH is received
Definition: signal.c:67
volatile sig_atomic_t SigInt
true after SIGINT is received
Definition: signal.c:66
int endwin(void)
void mutt_sig_exit_handler(int sig)
Notify the user and shutdown gracefully.
Definition: signal.c:125
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46