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-2025 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef SIG_H
24#define SIG_H
25
26#include "status.h"
27#include "win32.h"
28
29#define SIG_SOURCE_SOFT 0
30#define SIG_SOURCE_HARD 1
31/* CONNECTION_FAILED is also a "soft" status,
32 * It is thrown if a connection attempt fails
33 */
34#define SIG_SOURCE_CONNECTION_FAILED 2
35
36/*
37 * Signal information, including signal code
38 * and descriptive text.
39 */
41{
42 volatile int signal_received;
43 volatile int source;
44 const char *signal_text;
45};
46
47#define IS_SIG(c) ((c)->sig->signal_received)
48
49struct context;
50
51extern struct signal_info siginfo_static;
52
53int parse_signal(const char *signame);
54
55const char *signal_name(const int sig, const bool upper);
56
57const char *signal_description(const int signum, const char *sigtext);
58
59void throw_signal(const int signum);
60
61void throw_signal_soft(const int signum, const char *signal_text);
62
63void pre_init_signal_catch(void);
64
65void post_init_signal_catch(void);
66
67void restore_signal_state(void);
68
69void print_signal(const struct signal_info *si, const char *title, int msglevel);
70
71void print_status(struct context *c, struct status_output *so);
72
73void remap_signal(struct context *c);
74
75void signal_restart_status(const struct signal_info *si);
76
77bool process_signal(struct context *c);
78
79void register_signal(struct signal_info *si, int sig, const char *text);
80
82
88int signal_reset(struct signal_info *si, int signum);
89
90static inline void
92{
93#ifdef _WIN32
95#endif
96}
97
108static inline void
109get_signal(volatile int *sig)
110{
111#ifdef _WIN32
112 const int i = win32_signal_get(&win32_signal);
113#else
114 const int i = siginfo_static.signal_received;
115#endif
116 if (i && sig != &siginfo_static.signal_received)
117 {
118 *sig = i;
119 }
120}
121
122#endif /* ifndef SIG_H */
static void halt_non_edge_triggered_signals(void)
Definition sig.h:91
bool process_signal(struct context *c)
Definition sig.c:636
void signal_restart_status(const struct signal_info *si)
Definition sig.c:345
void post_init_signal_catch(void)
Definition sig.c:421
void throw_signal_soft(const int signum, const char *signal_text)
Throw a soft global signal.
Definition sig.c:204
void print_status(struct context *c, struct status_output *so)
Definition sig.c:478
const char * signal_name(const int sig, const bool upper)
Definition sig.c:91
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:228
int signal_reset(struct signal_info *si, int signum)
Clear the signal if its current value equals signum.
Definition sig.c:262
void process_explicit_exit_notification_timer_wakeup(struct context *c)
Definition sig.c:563
void pre_init_signal_catch(void)
Definition sig.c:392
void remap_signal(struct context *c)
Definition sig.c:588
const char * signal_description(const int signum, const char *sigtext)
Definition sig.c:105
void restore_signal_state(void)
Definition sig.c:460
void throw_signal(const int signum)
Throw a hard signal.
Definition sig.c:175
int parse_signal(const char *signame)
Definition sig.c:64
struct signal_info siginfo_static
Definition sig.c:44
void print_signal(const struct signal_info *si, const char *title, int msglevel)
Definition sig.c:290
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
Definition sig.h:109
Contains all state information for one tunnel.
Definition openvpn.h:474
const char * signal_text
Definition sig.h:44
volatile int signal_received
Definition sig.h:42
volatile int source
Definition sig.h:43
Definition sig.c:47
void win32_signal_close(struct win32_signal *ws)
Definition win32.c:599
int win32_signal_get(struct win32_signal *ws)
Definition win32.c:632