NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mutt_signal.c
Go to the documentation of this file.
1
22
28
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#if defined(USE_DEBUG_GRAPHVIZ) || defined(USE_DEBUG_BACKTRACE)
40#include "debug/lib.h"
41#endif
42
44static int IsEndwin = 0;
45
50static void curses_signal_handler(int sig)
51{
52 int save_errno = errno;
53 enum MuttCursorState old_cursor = MUTT_CURSOR_VISIBLE;
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 }
69
70 case SIGCONT:
71 if (!IsEndwin)
72 refresh();
73 mutt_curses_set_cursor(old_cursor);
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
94static void curses_exit_handler(int sig)
95{
97 endwin(); /* just to be safe */
99 mutt_sig_exit_handler(sig); /* DOES NOT RETURN */
100}
101
106static void curses_segv_handler(int sig)
107{
109 endwin(); /* just to be safe */
110#ifdef USE_DEBUG_BACKTRACE
112#endif
113#ifdef USE_DEBUG_GRAPHVIZ
114 dump_graphviz("segfault", NULL);
115#endif
116
117 // Chain the old SEGV handler, it could have been set by ASAN
118 if (OldSegvHandler)
119 OldSegvHandler(sig);
120
121 struct sigaction act = { 0 };
122 sigemptyset(&act.sa_mask);
123 act.sa_flags = 0;
124 act.sa_handler = SIG_DFL;
125 sigaction(sig, &act, NULL);
126
127 // Re-raise the signal to give outside handlers a chance to deal with it
128 raise(sig);
129}
130
GUI display the mailboxes in a side panel.
void show_backtrace(void)
Log the program's call stack.
Definition backtrace.c:40
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, const struct MailboxView *mv)
Dump NeoMutt data structures to GraphViz format.
Definition graphviz.c:1072
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:50
static void curses_segv_handler(int sig)
Catch a segfault and print a backtrace - Implements sig_handler_t -.
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.
Convenience wrapper for the library headers.
#define FALLTHROUGH
Definition lib.h:117
void mutt_temp_attachments_cleanup(void)
Delete all temporary attachments.
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:44
void mutt_signal_init(void)
Initialise the signal handling.
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:163
volatile sig_atomic_t SigWinch
true after SIGWINCH is received
Definition signal.c:69
volatile sig_atomic_t SigInt
true after SIGINT is received
Definition signal.c:68
sig_handler_t OldSegvHandler
Keep the old SEGV handler, it could have been set by ASAN.
Definition signal.c:66
int endwin(void)
void mutt_sig_exit_handler(int sig)
Notify the user and shutdown gracefully.
Definition signal.c:138
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49