MySQL 8.4.0
Source Code Documentation
mysql_signal_handler.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MY_SIGNAL_HANDLER_H
25#define MY_SIGNAL_HANDLER_H
26
28#if defined(_WIN32)
29struct siginfo_t;
30#else
31#include <signal.h>
32#endif
33
34// Note: siginfo_t is a complex structure. It should not be passed through the
35// component API boundary. This is an exception just for this service.
36using my_signal_handler_callback_t = void (*)(int, siginfo_t *, void *);
37
38/**
39 @ingroup group_components_services_inventory
40
41 A service to register/deregister a signal handler function callback
42
43 The server component signal handler will call this callback
44 if a signal occurs.
45 The callback needs to be signal reentrant safe code.
46 Otherwise no guaranees on what happens.
47
48 Usage example:
49 auto register_signal_handler_callback(my_signal_handler_callback_t callback)
50 -> bool {
51 SERVICE_PLACEHOLDER(my_signal_handler)->add(SIGSEGV, callback) == 0;
52 }
53 auto unregister_signal_handler_callback(my_signal_handler_callback_t
54 callback)
55 -> bool {
56 return SERVICE_PLACEHOLDER(my_signal_handler)->remove(SIGSEGV,
57 callback) == 0;
58 }
59
60 auto handle_segfault_signal(int signum) {
61 // Code to handle segfault
62 // ...
63 }
64
65 If this is used inside another component, at component init():
66 register_signal_handler_callback(&handle_segfault_signal)
67
68 At component deinit():
69 unregister_signal_handler_callback(&handle_segfault_signal)
70
71 @sa my_signal_handler_imp
72*/
73BEGIN_SERVICE_DEFINITION(my_signal_handler)
74/**
75 Register a callback that will be called when mysql server component handles a
76 fatal signal.
77
78 @note: Each registered callback needs to be unregistered by calling remove.
79
80 @param signal_no The signal number to listen to
81 @param callback Signal handling callback
82 @return Status of performed operation
83 @retval false registered successfully
84 @retval true failure to register
85
86 @sa my_host_application_signal
87*/
89 (int signal_no, my_signal_handler_callback_t callback));
90
91/**
92 Unregister a callback that was registered.
93
94 @param signal_no The signal number to listen to
95 @param callback Signal handling callback
96 @return Status of performed operation
97 @retval false unregistered successfully
98 @retval true failure to unregister
99
100 @sa my_host_application_signal
101*/
103 (int signal_no, my_signal_handler_callback_t callback));
104
105END_SERVICE_DEFINITION(my_signal_handler)
106
107#endif /* MY_SIGNAL_HANDLER_H */
void(*)(int, siginfo_t *, void *) my_signal_handler_callback_t
Definition: mysql_signal_handler.h:36
static mysql_service_status_t remove(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:137
static mysql_service_status_t add(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:127
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:112