OpenVPN
sig.h
Go to the documentation of this file.
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-2024 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 #define SIG_SOURCE_SOFT 0
31 #define SIG_SOURCE_HARD 1
32 /* CONNECTION_FAILED is also a "soft" status,
33  * It is thrown if a connection attempt fails
34  */
35 #define SIG_SOURCE_CONNECTION_FAILED 2
36 
37 /*
38  * Signal information, including signal code
39  * and descriptive text.
40  */
42 {
43  volatile int signal_received;
44  volatile int source;
45  const char *signal_text;
46 };
47 
48 #define IS_SIG(c) ((c)->sig->signal_received)
49 
50 struct context;
51 
52 extern struct signal_info siginfo_static;
53 
54 int parse_signal(const char *signame);
55 
56 const char *signal_name(const int sig, const bool upper);
57 
58 const char *signal_description(const int signum, const char *sigtext);
59 
60 void throw_signal(const int signum);
61 
62 void throw_signal_soft(const int signum, const char *signal_text);
63 
64 void pre_init_signal_catch(void);
65 
66 void post_init_signal_catch(void);
67 
68 void restore_signal_state(void);
69 
70 void print_signal(const struct signal_info *si, const char *title, int msglevel);
71 
72 void print_status(struct context *c, struct status_output *so);
73 
74 void remap_signal(struct context *c);
75 
76 void signal_restart_status(const struct signal_info *si);
77 
78 bool process_signal(struct context *c);
79 
80 void register_signal(struct signal_info *si, int sig, const char *text);
81 
83 
89 int signal_reset(struct signal_info *si, int signum);
90 
91 static inline void
93 {
94 #ifdef _WIN32
96 #endif
97 }
98 
109 static inline void
110 get_signal(volatile int *sig)
111 {
112 #ifdef _WIN32
113  const int i = win32_signal_get(&win32_signal);
114 #else
115  const int i = siginfo_static.signal_received;
116 #endif
117  if (i && sig != &siginfo_static.signal_received)
118  {
119  *sig = i;
120  }
121 }
122 
123 #endif /* ifndef SIG_H */
signal_info::signal_received
volatile int signal_received
Definition: sig.h:43
signal_info::signal_text
const char * signal_text
Definition: sig.h:45
win32.h
context
Contains all state information for one tunnel.
Definition: openvpn.h:476
signal_name
const char * signal_name(const int sig, const bool upper)
Definition: sig.c:93
print_signal
void print_signal(const struct signal_info *si, const char *title, int msglevel)
Definition: sig.c:294
signal_restart_status
void signal_restart_status(const struct signal_info *si)
Definition: sig.c:348
process_explicit_exit_notification_timer_wakeup
void process_explicit_exit_notification_timer_wakeup(struct context *c)
Definition: sig.c:564
throw_signal
void throw_signal(const int signum)
Throw a hard signal.
Definition: sig.c:177
win32_signal
Definition: win32.h:153
parse_signal
int parse_signal(const char *signame)
Definition: sig.c:66
throw_signal_soft
void throw_signal_soft(const int signum, const char *signal_text)
Throw a soft global signal.
Definition: sig.c:206
halt_non_edge_triggered_signals
static void halt_non_edge_triggered_signals(void)
Definition: sig.h:92
restore_signal_state
void restore_signal_state(void)
Definition: sig.c:466
status_output
Definition: status.h:48
signal_info::source
volatile int source
Definition: sig.h:44
pre_init_signal_catch
void pre_init_signal_catch(void)
Definition: sig.c:398
signame
Definition: sig.c:47
post_init_signal_catch
void post_init_signal_catch(void)
Definition: sig.c:427
win32_signal_get
int win32_signal_get(struct win32_signal *ws)
Definition: win32.c:639
win32_signal_close
void win32_signal_close(struct win32_signal *ws)
Definition: win32.c:605
signal_reset
int signal_reset(struct signal_info *si, int signum)
Clear the signal if its current value equals signum.
Definition: sig.c:266
signal_info
Definition: sig.h:41
register_signal
void register_signal(struct signal_info *si, int sig, const char *text)
Register a soft signal in the signal_info struct si respecting priority.
Definition: sig.c:231
process_signal
bool process_signal(struct context *c)
Definition: sig.c:637
signal_description
const char * signal_description(const int signum, const char *sigtext)
Definition: sig.c:107
get_signal
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
Definition: sig.h:110
siginfo_static
struct signal_info siginfo_static
Definition: sig.c:45
print_status
void print_status(struct context *c, struct status_output *so)
Definition: sig.c:484
remap_signal
void remap_signal(struct context *c)
Definition: sig.c:588
status.h