Signal handling. More...
#include "config.h"
#include <signal.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "signal2.h"
Go to the source code of this file.
Functions | |
int | endwin (void) |
static void | exit_print_uint (unsigned int n) |
AS-safe version of printf("%u", n) | |
static void | exit_print_int (int n) |
AS-safe version of printf("%d", n) | |
static void | exit_print_string (const char *str) |
AS-safe version of printf("%s", str) | |
void | mutt_sig_empty_handler (int sig) |
Dummy signal handler. | |
void | mutt_sig_exit_handler (int sig) |
Notify the user and shutdown gracefully. | |
void | mutt_sig_init (sig_handler_t sig_fn, sig_handler_t exit_fn, sig_handler_t segv_fn) |
Initialise the signal handling. | |
void | mutt_sig_block (void) |
Block signals during critical operations. | |
void | mutt_sig_unblock (void) |
Restore previously blocked signals. | |
void | mutt_sig_block_system (void) |
Block signals before calling exec() | |
void | mutt_sig_unblock_system (bool restore) |
Restore previously blocked signals. | |
void | mutt_sig_allow_interrupt (bool allow) |
Allow/disallow Ctrl-C (SIGINT) | |
void | mutt_sig_reset_child_signals (void) |
Reset ignored signals back to the default. | |
void | assertion_dump (const char *file, int line, const char *func, const char *cond) |
Dump some debugging info before we stop the program. | |
Variables | |
static sigset_t | Sigset |
A set of signals used by mutt_sig_block(), mutt_sig_unblock() | |
static sigset_t | SigsetSys |
A set of signals used by mutt_sig_block_system(), mutt_sig_unblock_system() | |
static struct sigaction | SysOldInt |
Backup of SIGINT handler, when mutt_sig_block_system() is called. | |
static struct sigaction | SysOldQuit |
Backup of SIGQUIT handler, when mutt_sig_block_system() is called. | |
static bool | SignalsBlocked |
true when signals are blocked, e.g. | |
static bool | SysSignalsBlocked |
true when system signals are blocked, e.g. | |
static sig_handler_t | SigHandler = mutt_sig_empty_handler |
Function to handle other signals, e.g. SIGINT (2) | |
static sig_handler_t | ExitHandler = mutt_sig_exit_handler |
Function to handle SIGTERM (15), SIGHUP (1), SIGQUIT (3) signals. | |
static sig_handler_t | SegvHandler = mutt_sig_exit_handler |
Function to handle SIGSEGV (11) signals. | |
volatile sig_atomic_t | SigInt |
true after SIGINT is received | |
volatile sig_atomic_t | SigWinch |
true after SIGWINCH is received | |
Signal handling.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file signal.c.
int endwin | ( | void | ) |
|
static |
AS-safe version of printf("%u", n)
n | Number to be printed |
Definition at line 73 of file signal.c.
|
static |
|
static |
void mutt_sig_empty_handler | ( | int | sig | ) |
void mutt_sig_exit_handler | ( | int | sig | ) |
Notify the user and shutdown gracefully.
sig | Signal number, e.g. SIGINT |
Definition at line 125 of file signal.c.
void mutt_sig_init | ( | sig_handler_t | sig_fn, |
sig_handler_t | exit_fn, | ||
sig_handler_t | segv_fn | ||
) |
Initialise the signal handling.
sig_fn | Function to handle signals |
exit_fn | Function to call on uncaught signals |
segv_fn | Function to call on a segfault (Segmentation Violation) |
Set up handlers to ignore or catch signals of interest. We use three handlers for the signals we want to catch, ignore, or exit.
Definition at line 150 of file signal.c.
void mutt_sig_block | ( | void | ) |
Block signals during critical operations.
It's important that certain signals don't interfere with critical operations. Call mutt_sig_unblock() to restore the signals' behaviour.
Definition at line 212 of file signal.c.
void mutt_sig_unblock | ( | void | ) |
void mutt_sig_block_system | ( | void | ) |
Block signals before calling exec()
It's important that certain signals don't interfere with the child process. Call mutt_sig_unblock_system() to restore the signals' behaviour.
Definition at line 245 of file signal.c.
void mutt_sig_unblock_system | ( | bool | restore | ) |
Restore previously blocked signals.
restore | If true, restore previous SIGINT, SIGQUIT behaviour |
Definition at line 269 of file signal.c.
void mutt_sig_allow_interrupt | ( | bool | allow | ) |
Allow/disallow Ctrl-C (SIGINT)
allow | True to allow Ctrl-C to interrupt signals |
Allow the user to interrupt some long operations.
Definition at line 300 of file signal.c.
void mutt_sig_reset_child_signals | ( | void | ) |
Reset ignored signals back to the default.
See sigaction(2): A child created via fork(2) inherits a copy of its parent's signal dispositions. During an execve(2), the dispositions of handled signals are reset to the default; the dispositions of ignored signals are left unchanged.
Definition at line 321 of file signal.c.
void assertion_dump | ( | const char * | file, |
int | line, | ||
const char * | func, | ||
const char * | cond | ||
) |
Dump some debugging info before we stop the program.
file | Source file |
line | Line of source |
func | Function |
cond | Assertion condition |
Definition at line 346 of file signal.c.
|
static |
A set of signals used by mutt_sig_block(), mutt_sig_unblock()
|
static |
A set of signals used by mutt_sig_block_system(), mutt_sig_unblock_system()
|
static |
Backup of SIGINT handler, when mutt_sig_block_system() is called.
|
static |
Backup of SIGQUIT handler, when mutt_sig_block_system() is called.
|
static |
|
static |
true when system signals are blocked, e.g.
SIGINT, SIGQUIT
|
static |
|
static |
|
static |