45 static void add(
void (*fn)(
SignalSafe,
const char*) ,
const char * ) ;
48 static void ignore(
int ) ;
52 static void install(
int ,
Handler ) ;
53 static void installHandler(
int ) ;
54 static bool ignored(
int ) ;
64 static Link * m_head ;
65 static Link * m_tail ;
68 G::CleanupImp::Link * G::CleanupImp::m_head = NULL ;
69 G::CleanupImp::Link * G::CleanupImp::m_tail = NULL ;
86 void G::CleanupImp::init()
92 installHandler( SIGTERM ) ;
93 installHandler( SIGINT ) ;
94 installHandler( SIGHUP ) ;
95 installHandler( SIGQUIT ) ;
102 Link * p =
new Link ;
108 if( m_head == NULL ) init() ;
109 if( m_tail != NULL ) m_tail->next = p ;
111 if( m_head == NULL ) m_head = p ;
114 void G::CleanupImp::installHandler(
int signum )
116 if( ignored(signum) )
117 G_DEBUG(
"G::CleanupImp::installHandler: signal " << signum <<
" is ignored" ) ;
124 install( signum , NULL ) ;
127 bool G::CleanupImp::ignored(
int signum )
129 static struct sigaction zero_action ;
130 struct sigaction action( zero_action ) ;
131 if( ::sigaction( signum , NULL , &action ) )
132 throw Cleanup::Error(
"sigaction" ) ;
133 return action.sa_handler == SIG_IGN ;
136 void G::CleanupImp::install(
int signum ,
Handler fn )
139 static struct sigaction zero_action ;
140 struct sigaction action( zero_action ) ;
141 action.sa_handler = fn ? fn : SIG_DFL ;
142 if( ::sigaction( signum , &action , NULL ) && fn != NULL )
143 throw Cleanup::Error(
"sigaction" ) ;
148 static struct sigaction zero_action ;
149 struct sigaction action( zero_action ) ;
150 action.sa_handler = SIG_IGN ;
151 if( ::sigaction( signum , &action , NULL ) )
152 throw Cleanup::Error(
"sigaction" ) ;
158 for(
const Link * p = m_head ; p != NULL ; p = p->next )
An empty structure that is used to indicate a signal-safe, reentrant implementation.
static void add(void(*fn)(SignalSafe, const char *), const char *)
A class which acquires the process's special privileges on construction and releases them on destruct...
void gcleanup_unix_handler_(int signum)
static int errno_()
Returns the process's current 'errno' value.
static void init()
An optional early-initialisation function.
static void callHandlers()
A private implementation class used by G::Cleanup.
static void installDefault(int)
static void add(void(*fn)(SignalSafe, const char *), const char *arg)
Adds the given handler to the list which are to be called when the process terminates abnormally...