E-MailRelay
Classes | Static Public Member Functions | List of all members
G::Cleanup Class Reference

A static interface for registering cleanup functions that are called when the process terminates abnormally. More...

#include <gcleanup.h>

Classes

struct  Block
 A RAII class to temporarily block signal delivery. More...
 

Static Public Member Functions

static void init ()
 An optional early-initialisation function. May be called more than once. More...
 
static void add (bool(*fn)(SignalSafe, const char *), const char *arg)
 Adds the given handler to the list of handlers that are to be called when the process terminates abnormally. More...
 
static void atexit (bool active=true)
 Ensures that the cleanup functions are also called via atexit(), in addition to abnormal-termination signals. More...
 
static void block () noexcept
 Temporarily blocks signals until release()d. More...
 
static void release () noexcept
 Releases block()ed signals. More...
 
static const char * strdup (const char *)
 A strdup() function that makes it clear in the stack trace that leaks are expected. More...
 
static const char * strdup (const std::string &)
 A strdup() function that makes it clear in the stack trace that leaks are expected. More...
 

Detailed Description

A static interface for registering cleanup functions that are called when the process terminates abnormally.

On unix this relates to signals like SIGTERM, SIGINT etc.

Definition at line 39 of file gcleanup.h.

Member Function Documentation

◆ add()

void G::Cleanup::add ( bool(*)(SignalSafe, const char *)  fn,
const char *  arg 
)
static

Adds the given handler to the list of handlers that are to be called when the process terminates abnormally.

The handler function must be fully reentrant, hence the SignalSafe dummy parameter. The 'arg' pointer is kept.

Definition at line 116 of file gcleanup_unix.cpp.

◆ atexit()

void G::Cleanup::atexit ( bool  active = true)
static

Ensures that the cleanup functions are also called via atexit(), in addition to abnormal-termination signals.

This can be useful when ancient third-party library code (eg. Xlib) might call exit(), but be careful to disable these exit handlers before normal termination by calling atexit(false).

Definition at line 121 of file gcleanup_unix.cpp.

◆ block()

void G::Cleanup::block ( )
staticnoexcept

Temporarily blocks signals until release()d.

This should be used before creating threads so that only the main thread does signal handling.

Definition at line 126 of file gcleanup_unix.cpp.

◆ init()

void G::Cleanup::init ( )
static

An optional early-initialisation function. May be called more than once.

Definition at line 111 of file gcleanup_unix.cpp.

◆ release()

void G::Cleanup::release ( )
staticnoexcept

Releases block()ed signals.

Definition at line 131 of file gcleanup_unix.cpp.

◆ strdup() [1/2]

const char * G::Cleanup::strdup ( const char *  p)
static

A strdup() function that makes it clear in the stack trace that leaks are expected.

Definition at line 136 of file gcleanup_unix.cpp.

◆ strdup() [2/2]

const char * G::Cleanup::strdup ( const std::string &  s)
static

A strdup() function that makes it clear in the stack trace that leaks are expected.

Definition at line 141 of file gcleanup_unix.cpp.


The documentation for this class was generated from the following files: