MySQL 8.4.3
Source Code Documentation
signal_handler.cc File Reference
#include "my_config.h"
#include "sql/signal_handler.h"
#include <signal.h>
#include <sys/types.h>
#include <time.h>
#include <algorithm>
#include <atomic>
#include "lex_string.h"
#include "my_inttypes.h"
#include <unistd.h>
#include "my_macros.h"
#include "my_stacktrace.h"
#include "my_sys.h"
#include "my_time.h"
#include "sql/mysqld.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"

Macros

#define SIGNAL_FMT   "signal %d"
 

Functions

static void print_extra_signal_information (int sig, siginfo_t *info)
 
static void print_fatal_signal (int sig, siginfo_t *info)
 This function will try to dump relevant debugging information to stderr. More...
 
void handle_fatal_signal (int sig, siginfo_t *info, void *ucontext)
 Handler for fatal signals. More...
 
void my_server_abort ()
 This is a wrapper around abort() which ensures that abort() will be called exactly once, as calling it more than once might cause following problems: When original abort() is called there is a signal processing triggered, but only the first abort() causes the signal handler to be called, all other abort()s called by the other threads will cause immediate exit() call, which will also terminate the first abort() processing within the signal handler, aborting stacktrace printing, core writeout or any other processing. More...
 

Variables

static std::atomic< bool > s_handler_being_processed {false}
 This is used to check if the signal handler is not called again while already handling the previous signal, as may happen when either another thread triggers it, or a bug in handling causes abort again. More...
 
static std::atomic< bool > s_fatal_info_printed {false}
 Used to remember if the fatal info was already printed. More...
 
std::atomic< my_signal_handler_callback_tg_fatal_callback
 

Macro Definition Documentation

◆ SIGNAL_FMT

#define SIGNAL_FMT   "signal %d"

Function Documentation

◆ handle_fatal_signal()

void handle_fatal_signal ( int  sig,
siginfo_t *  info,
void *  ucontext 
)

Handler for fatal signals.

Fatal events (seg.fault, bus error etc.) will trigger this signal handler. The handler will try to dump relevant debugging information to stderr and dump a core image.

Signal handlers can only use a set of 'safe' system calls and library functions.

Parameters
sigSignal number
infoMisc. information about the signal, see man sigaction(2).
ucontextPointer to a ucontext_t structure. "Commonly, the handler function doesn't make any use of the third argument."

◆ my_server_abort()

void my_server_abort ( )

This is a wrapper around abort() which ensures that abort() will be called exactly once, as calling it more than once might cause following problems: When original abort() is called there is a signal processing triggered, but only the first abort() causes the signal handler to be called, all other abort()s called by the other threads will cause immediate exit() call, which will also terminate the first abort() processing within the signal handler, aborting stacktrace printing, core writeout or any other processing.

◆ print_extra_signal_information()

static void print_extra_signal_information ( int  sig,
siginfo_t *  info 
)
static

◆ print_fatal_signal()

static void print_fatal_signal ( int  sig,
siginfo_t *  info 
)
static

This function will try to dump relevant debugging information to stderr.

It may be called as part of the signal handler. This fact limits library calls that we can perform and much more,

See also
handle_fatal_signal
Parameters
sigSignal number
infoMisc. information about the signal, see man sigaction(2).

Variable Documentation

◆ g_fatal_callback

std::atomic<my_signal_handler_callback_t> g_fatal_callback

◆ s_fatal_info_printed

std::atomic<bool> s_fatal_info_printed {false}
static

Used to remember if the fatal info was already printed.

The info can be printed from user threads, but in the fatal signal handler we want to print it if and only if the info was not yet printed. User threads after printing the info will call abort which will call the handler.

◆ s_handler_being_processed

std::atomic<bool> s_handler_being_processed {false}
static

This is used to check if the signal handler is not called again while already handling the previous signal, as may happen when either another thread triggers it, or a bug in handling causes abort again.