OpenVPN
Data Structures | Macros | Functions | Variables
sig.c File Reference
#include "syshead.h"
#include "buffer.h"
#include "error.h"
#include "win32.h"
#include "init.h"
#include "status.h"
#include "sig.h"
#include "occ.h"
#include "manage.h"
#include "openvpn.h"
#include "memdbg.h"
Include dependency graph for sig.c:

Go to the source code of this file.

Data Structures

struct  signame
 

Macros

#define SM_UNDEF   0
 
#define SM_PRE_INIT   1
 
#define SM_POST_INIT   2
 

Functions

int parse_signal (const char *signame)
 
static int signal_priority (int sig)
 
const char * signal_name (const int sig, const bool upper)
 
const char * signal_description (const int signum, const char *sigtext)
 
static void block_async_signals (void)
 Block (i.e., defer) all unix signals. More...
 
static void unblock_async_signals (void)
 Unblock all unix signals. More...
 
static bool try_throw_signal (struct signal_info *si, int signum, int source)
 Private function for registering a signal in the specified signal_info struct. More...
 
void throw_signal (const int signum)
 Throw a hard signal. More...
 
void throw_signal_soft (const int signum, const char *signal_text)
 Throw a soft global signal. More...
 
void register_signal (struct signal_info *si, int signum, const char *signal_text)
 Register a soft signal in the signal_info struct si respecting priority. More...
 
int signal_reset (struct signal_info *si, int signum)
 Clear the signal if its current value equals signum. More...
 
void print_signal (const struct signal_info *si, const char *title, int msglevel)
 
void signal_restart_status (const struct signal_info *si)
 
void pre_init_signal_catch (void)
 
void post_init_signal_catch (void)
 
void halt_low_priority_signals (void)
 
void restore_signal_state (void)
 
void print_status (struct context *c, struct status_output *so)
 
static void process_explicit_exit_notification_init (struct context *c)
 
void process_explicit_exit_notification_timer_wakeup (struct context *c)
 
void remap_signal (struct context *c)
 
static void process_sigusr2 (struct context *c)
 
static bool process_sigterm (struct context *c)
 
static void remap_restart_signals (struct context *c)
 If a soft restart signal is received during exit-notification, it implies the event loop cannot continue: remap to SIGTERM to exit promptly. More...
 
bool process_signal (struct context *c)
 

Variables

struct signal_info siginfo_static
 
static const struct signame signames []
 
static unsigned long long ignored_hard_signals_mask
 
static int signal_mode
 

Macro Definition Documentation

◆ SM_POST_INIT

#define SM_POST_INIT   2

Definition at line 394 of file sig.c.

◆ SM_PRE_INIT

#define SM_PRE_INIT   1

Definition at line 393 of file sig.c.

◆ SM_UNDEF

#define SM_UNDEF   0

Definition at line 392 of file sig.c.

Function Documentation

◆ block_async_signals()

static void block_async_signals ( void  )
inlinestatic

Block (i.e., defer) all unix signals.

Used while directly modifying the volatile elements of siginfo_static.

Definition at line 125 of file sig.c.

Referenced by register_signal(), signal_reset(), throw_signal(), and throw_signal_soft().

◆ halt_low_priority_signals()

void halt_low_priority_signals ( void  )

Definition at line 451 of file sig.c.

References CLEAR, and ignored_hard_signals_mask.

Referenced by process_explicit_exit_notification_init().

◆ parse_signal()

int parse_signal ( const char *  signame)

Definition at line 66 of file sig.c.

References signames, SIZE, signame::upper, and signame::value.

Referenced by man_signal().

◆ post_init_signal_catch()

void post_init_signal_catch ( void  )

Definition at line 427 of file sig.c.

References CLEAR, signal_mode, and SM_POST_INIT.

Referenced by init_instance_handle_signals(), and restore_signal_state().

◆ pre_init_signal_catch()

void pre_init_signal_catch ( void  )

◆ print_signal()

void print_signal ( const struct signal_info si,
const char *  title,
int  msglevel 
)

◆ print_status()

void print_status ( struct context c,
struct status_output so 
)

◆ process_explicit_exit_notification_init()

static void process_explicit_exit_notification_init ( struct context c)
static

◆ process_explicit_exit_notification_timer_wakeup()

void process_explicit_exit_notification_timer_wakeup ( struct context c)

◆ process_signal()

bool process_signal ( struct context c)

◆ process_sigterm()

static bool process_sigterm ( struct context c)
static

◆ process_sigusr2()

static void process_sigusr2 ( struct context c)
static

Definition at line 597 of file sig.c.

References M_INFO, print_status(), context::sig, signal_reset(), status_close(), and status_open().

Referenced by process_signal().

◆ register_signal()

void register_signal ( struct signal_info si,
int  signum,
const char *  signal_text 
)

◆ remap_restart_signals()

static void remap_restart_signals ( struct context c)
static

If a soft restart signal is received during exit-notification, it implies the event loop cannot continue: remap to SIGTERM to exit promptly.

Hard restart signals are ignored during exit notification wait.

Definition at line 624 of file sig.c.

References context::c2, event_timeout_defined(), context_2::explicit_exit_notification_interval, M_INFO, msg, register_signal(), context::sig, SIG_SOURCE_HARD, signal_name(), signal_info::signal_received, and signal_info::source.

Referenced by process_signal().

◆ remap_signal()

void remap_signal ( struct context c)

◆ restore_signal_state()

void restore_signal_state ( void  )

◆ signal_description()

const char* signal_description ( const int  signum,
const char *  sigtext 
)

Definition at line 107 of file sig.c.

References signal_name().

Referenced by do_close_tun().

◆ signal_name()

const char* signal_name ( const int  sig,
const bool  upper 
)

◆ signal_priority()

static int signal_priority ( int  sig)
static

Definition at line 80 of file sig.c.

References signame::priority, signames, SIZE, and signame::value.

Referenced by try_throw_signal().

◆ signal_reset()

int signal_reset ( struct signal_info si,
int  signum 
)

Clear the signal if its current value equals signum.

If signum is zero the signal is cleared independent of its current value. Returns the current value of the signal.

Definition at line 266 of file sig.c.

References block_async_signals(), D_SIGNAL_DEBUG, msg, SIG_SOURCE_SOFT, siginfo_static, signal_name(), signal_info::signal_received, signal_info::signal_text, signal_info::source, and unblock_async_signals().

Referenced by link_socket_init_phase2(), multi_process_signal(), multi_push_restart_schedule_exit(), openvpn_getaddrinfo(), openvpn_main(), pre_init_signal_catch(), process_explicit_exit_notification_init(), and process_sigusr2().

◆ signal_restart_status()

void signal_restart_status ( const struct signal_info si)

◆ throw_signal()

void throw_signal ( const int  signum)

Throw a hard signal.

Called from management and when windows signals are received through ctrl-c, exit event etc.

Definition at line 177 of file sig.c.

Referenced by link_socket_init_phase2(), man_connect(), man_signal(), multi_process_timeout(), win32_signal_get(), and win_ctrl_handler().

◆ throw_signal_soft()

void throw_signal_soft ( const int  signum,
const char *  signal_text 
)

Throw a soft global signal.

Used to register internally generated signals due to errors that require a restart or exit, or restart requests received from the server. A textual description of the signal may be provided.

Definition at line 206 of file sig.c.

References block_async_signals(), D_SIGNAL_DEBUG, msg, SIG_SOURCE_SOFT, siginfo_static, signal_name(), signal_info::signal_received, signal_info::signal_text, try_throw_signal(), and unblock_async_signals().

Referenced by apply_pull_filter(), do_preresolve(), man_connect(), and man_reset_client_socket().

◆ try_throw_signal()

static bool try_throw_signal ( struct signal_info si,
int  signum,
int  source 
)
static

Private function for registering a signal in the specified signal_info struct.

This could be the global siginfo_static or a context specific signinfo struct.

A signal is allowed to override an already registered one only if it has a higher priority. Returns true if the signal is set, false otherwise.

Do not call any "AS-unsafe" functions such as printf from here as this may be called from signal_handler().

Definition at line 160 of file sig.c.

References signal_priority(), signal_info::signal_received, and signal_info::source.

Referenced by register_signal(), throw_signal(), and throw_signal_soft().

◆ unblock_async_signals()

static void unblock_async_signals ( void  )
inlinestatic

Unblock all unix signals.

Definition at line 138 of file sig.c.

Referenced by register_signal(), signal_reset(), throw_signal(), and throw_signal_soft().

Variable Documentation

◆ ignored_hard_signals_mask

unsigned long long ignored_hard_signals_mask
static

Definition at line 63 of file sig.c.

Referenced by halt_low_priority_signals(), and throw_signal().

◆ siginfo_static

struct signal_info siginfo_static

◆ signal_mode

int signal_mode
static

Definition at line 395 of file sig.c.

Referenced by post_init_signal_catch(), pre_init_signal_catch(), and restore_signal_state().

◆ signames

const struct signame signames[]
static
Initial value:
= {
{ SIGINT, 5, "SIGINT", "sigint"},
{ SIGTERM, 4, "SIGTERM", "sigterm" },
{ SIGHUP, 3, "SIGHUP", "sighup" },
{ SIGUSR1, 2, "SIGUSR1", "sigusr1" },
{ SIGUSR2, 1, "SIGUSR2", "sigusr2" }
}

Definition at line 54 of file sig.c.

Referenced by parse_signal(), signal_name(), and signal_priority().