1 /*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2022 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24 #ifndef SIG_H
25 #define SIG_H
26
27 #include "status.h"
28 #include "win32.h"
29
30
31
32 #define SIG_SOURCE_SOFT 0
33 #define SIG_SOURCE_HARD 1
34 /* CONNECTION_FAILED is also a "soft" status,
35 * It is thrown if a connection attempt fails
36 */
37 #define SIG_SOURCE_CONNECTION_FAILED 2
38
39 /*
40 * Signal information, including signal code
41 * and descriptive text.
42 */
43 struct signal_info
44 {
45 volatile int signal_received;
46 volatile int source;
47 const char *signal_text;
48 };
49
50 #define IS_SIG(c) ((c)->sig->signal_received)
51
52 struct context;
53
54 extern struct signal_info siginfo_static;
55
56 int parse_signal(const char *signame);
57
58 const char *signal_name(const int sig, const bool upper);
59
60 const char *signal_description(const int signum, const char *sigtext);
61
62 void throw_signal(const int signum);
63
64 void throw_signal_soft(const int signum, const char *signal_text);
65
66 void pre_init_signal_catch(void);
67
68 void post_init_signal_catch(void);
69
70 void restore_signal_state(void);
71
72 void print_signal(const struct signal_info *si, const char *title, int msglevel);
73
74 void print_status(const struct context *c, struct status_output *so);
75
76 void remap_signal(struct context *c);
77
78 void signal_restart_status(const struct signal_info *si);
79
80 bool process_signal(struct context *c);
81
82 void register_signal(struct context *c, int sig, const char *text);
83
84 void process_explicit_exit_notification_timer_wakeup(struct context *c);
85
86 #ifdef _WIN32
87
88 static inline void
get_signal(volatile int * sig)89 get_signal(volatile int *sig)
90 {
91 *sig = win32_signal_get(&win32_signal);
92 }
93
94 static inline void
halt_non_edge_triggered_signals(void)95 halt_non_edge_triggered_signals(void)
96 {
97 win32_signal_close(&win32_signal);
98 }
99
100 #else /* ifdef _WIN32 */
101
102 static inline void
get_signal(volatile int * sig)103 get_signal(volatile int *sig)
104 {
105 const int i = siginfo_static.signal_received;
106 if (i)
107 {
108 *sig = i;
109 }
110 }
111
112 static inline void
halt_non_edge_triggered_signals(void)113 halt_non_edge_triggered_signals(void)
114 {
115 }
116
117 #endif /* ifdef _WIN32 */
118
119 #endif /* ifndef SIG_H */
120