libassa 3.5.1
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
ASSA::SigAction Class Reference

#include <SigAction.h>

Public Member Functions

 SigAction ()
 Default constructor creates SigAction object with null-action.
 
 SigAction (C_SIG_HANDLER handler_, SigSet *sig_mask_=0, int flags_=0)
 Construct a SigAction object with "C" signal handler function.
 
 SigAction (C_SIG_HANDLER handler_, int signum_, SigSet *sig_mask_=0, int flags_=0)
 Construct a SigAction with "C" signal handler function and change program's disposition for signum_ immediately.
 
int register_action (int signum_, SigAction *oaction_=0)
 Register this object as current disposition for signal signum_, and store old disposition in oaction_, if not NULL.
 
int restore_action (int signum_, SigAction &oaction_)
 Change object's disposition to oaction_, and install it as current disposition for the signal signum_.
 
int retrieve_action (int signum_)
 Retrieve current disposition for the signal signum_ into this object.
 
void action (SIGACTION *sa_)
 Set sigaction structure to sa_.
 
SIGACTIONaction ()
 Retrieve current sigaction.
 
void flags (int new_flags_)
 Set signal flags to new_flags_.
 
int flags ()
 Retrieve current flags.
 
void mask (SigSet &mask_set_)
 Set new signal mask mask_set_.
 
SigSet mask ()
 Retrieve current signal mask.
 
void handler (C_SIG_HANDLER sha_)
 Set new signal handler to function pointer sha_.
 
C_SIG_HANDLER handler ()
 Retrieve current signal handler function.
 
 operator SIGACTION * ()
 Conversion operator that converts SigAction to a pointer to the internal struct sigaction data member for direct use with C-library functions.
 

Private Attributes

SIGACTION m_sa
 sigaction structure itself
 

Detailed Description

Definition at line 94 of file SigAction.h.

Constructor & Destructor Documentation

◆ SigAction() [1/3]

ASSA::SigAction::SigAction ( )
inline

Default constructor creates SigAction object with null-action.

Definition at line 220 of file SigAction.h.

222{
223 trace_with_mask("SigAction::SigAction", SIGACT);
224
225 m_sa.sa_flags = 0;
226 sigemptyset(&m_sa.sa_mask);
227 *(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) 0;
228}
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
void(* C_SIG_HANDLER)(int)
Definition SigAction.h:28
SIGACTION m_sa
sigaction structure itself
Definition SigAction.h:213
@ SIGACT
Class SigACtion messages
Definition LogMask.h:48

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ SigAction() [2/3]

ASSA::SigAction::SigAction ( C_SIG_HANDLER  handler_,
SigSet sig_mask_ = 0,
int  flags_ = 0 
)
inline

Construct a SigAction object with "C" signal handler function.

This constructor doesn't install any actions - it is merely a shell for actiono to be installed for any signal(s). Thus, you can reuse the same object for number of differen signals.

Parameters
handler_"C" signal handler function to call.
sig_mask_Set of signals to block while handler_ is active.
flags_Controls behavior of signal handler (OS-specific: see Available Options: section of documentation).

Definition at line 231 of file SigAction.h.

235{
236 trace_with_mask("SigAction::SigAction(,,)", SIGACT);
237
238 m_sa.sa_flags = flags_;
239 if (sig_mask_ == NULL) {
240 sigemptyset(&m_sa.sa_mask);
241 }
242 else {
243 /*---
244 here, suppose to do bitwise structure assignment,
245 but does it really do so?
246 = *sig_mask_
247 = *(sig_mask_.operator *())
248 = *(SigSet *tmp = &sig_mask_.m_sa) ????
249 ---*/
250 m_sa.sa_mask = **sig_mask_;
251 }
252 *(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) handler_;
253}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ SigAction() [3/3]

ASSA::SigAction::SigAction ( C_SIG_HANDLER  handler_,
int  signum_,
SigSet sig_mask_ = 0,
int  flags_ = 0 
)
inline

Construct a SigAction with "C" signal handler function and change program's disposition for signum_ immediately.

First argument is the "C" function. It cannot be a non-static C++ class member function. This function pretty much simulates C-like approach the the signal handling. For C++ member function approach, see SigHandler & Co.

Parameters
handler_"C" signal handler function to call.
signum_Signal which disposition is to change.
sig_mask_Set of signals to block while handler_ is active.
flags_Controls behavior of signal handler (OS-specific: see Available Options: section of documentation).

Definition at line 256 of file SigAction.h.

261{
262 trace_with_mask("SigAction::SigAction(,,,)", SIGACT);
263
264 m_sa.sa_flags = flags_;
265 if (sig_mask_ == NULL) {
266 sigemptyset(&m_sa.sa_mask);
267 }
268 else {
269 /*--- same problem as above... ---*/
270 m_sa.sa_mask = **sig_mask_;
271 }
272 *(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) handler_;
273
274 /*--- installing disposition... ---*/
275 sigaction (signum_, &m_sa, 0);
276}

References m_sa, ASSA::SIGACT, and trace_with_mask.

Member Function Documentation

◆ action() [1/2]

SIGACTION * ASSA::SigAction::action ( )
inline

Retrieve current sigaction.

Returns
Pointer to an internal struct sigaction.

Definition at line 287 of file SigAction.h.

289{
290 trace_with_mask("SigAction::action", SIGACT);
291
292 return &m_sa;
293}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ action() [2/2]

void ASSA::SigAction::action ( SIGACTION sa_)
inline

Set sigaction structure to sa_.

Parameters
sa_New value for internal struct sigaction.

Definition at line 279 of file SigAction.h.

281{
282 trace_with_mask("SigAction::action", SIGACT);
283 m_sa = *sa_;
284}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ flags() [1/2]

int ASSA::SigAction::flags ( )
inline

Retrieve current flags.

Returns
Value of current flags for this action.

Definition at line 305 of file SigAction.h.

307{
308 trace_with_mask("int SigAction::flags()", SIGACT);
309
310 return m_sa.sa_flags;
311}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ flags() [2/2]

void ASSA::SigAction::flags ( int  new_flags_)
inline

Set signal flags to new_flags_.

Parameters
new_flags_New flags for this action.

Definition at line 296 of file SigAction.h.

298{
299 trace_with_mask("void SigAction::flags()", SIGACT);
300
301 m_sa.sa_flags = new_flags_;
302}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ handler() [1/2]

C_SIG_HANDLER ASSA::SigAction::handler ( )
inline

Retrieve current signal handler function.

Definition at line 342 of file SigAction.h.

344{
345 trace_with_mask("C_SIG_HANDLER SigAction::handler()", SIGACT);
346
347 return (C_SIG_HANDLER) m_sa.sa_handler;
348}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ handler() [2/2]

void ASSA::SigAction::handler ( C_SIG_HANDLER  sha_)
inline

Set new signal handler to function pointer sha_.

Definition at line 333 of file SigAction.h.

335{
336 trace_with_mask("void SigAction::handler()", SIGACT);
337
338 *(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) sha_;
339}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ mask() [1/2]

SigSet ASSA::SigAction::mask ( )
inline

Retrieve current signal mask.

Definition at line 323 of file SigAction.h.

325{
326 trace_with_mask("SigSet SigAction::mask()", SIGACT);
327
328 SigSet tmpset(&m_sa.sa_mask);
329 return tmpset;
330}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ mask() [2/2]

void ASSA::SigAction::mask ( SigSet mask_set_)
inline

Set new signal mask mask_set_.

Definition at line 314 of file SigAction.h.

316{
317 trace_with_mask("void SigAction::mask()", SIGACT);
318
319 m_sa.sa_mask = *mask_set_;
320}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ operator SIGACTION *()

ASSA::SigAction::operator SIGACTION * ( )
inline

Conversion operator that converts SigAction to a pointer to the internal struct sigaction data member for direct use with C-library functions.

Definition at line 351 of file SigAction.h.

352{
353 trace_with_mask("SigAction::operator SIGACTION * ()", SIGACT);
354
355 return &m_sa;
356}

References ASSA::SIGACT, and trace_with_mask.

◆ register_action()

int ASSA::SigAction::register_action ( int  signum_,
SigAction oaction_ = 0 
)
inline

Register this object as current disposition for signal signum_, and store old disposition in oaction_, if not NULL.

This function installs C_SIG_HANDLER this object represents, thus simulating C-like approach to signal handling.

Parameters
signum_Signal which disposition to install.
oaction_Placeholder for the old disposition.
Returns
0 on success, -1 on error, with errno indicating the error.

Definition at line 359 of file SigAction.h.

361{
362 trace_with_mask("SigAction::register_action()", SIGACT);
363
364 /*--- place here recursive mutex lock to guard ... ---*/
365 struct sigaction *osa = oaction_ == 0 ? 0 : oaction_->action();
366 return sigaction(signum_, &m_sa, osa);
367}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ restore_action()

int ASSA::SigAction::restore_action ( int  signum_,
SigAction oaction_ 
)
inline

Change object's disposition to oaction_, and install it as current disposition for the signal signum_.

Parameters
signum_Signal which disposition to restore.
oaction_Disposition to restore.
Returns
0 on success, -1 on error, with errno indicating the error.

Definition at line 370 of file SigAction.h.

372{
373 trace_with_mask("SigAction::restore_action()", SIGACT);
374
375 m_sa = *oaction_.action();
376 return sigaction(signum_, &m_sa, 0);
377}

References m_sa, ASSA::SIGACT, and trace_with_mask.

◆ retrieve_action()

int ASSA::SigAction::retrieve_action ( int  signum_)
inline

Retrieve current disposition for the signal signum_ into this object.

Parameters
signum_Signal number
Returns
0 on success, -1 on error, with errno indicating the error.

Definition at line 380 of file SigAction.h.

382{
383 trace_with_mask("SigAction::retrieve_action()", SIGACT);
384
385 return sigaction(signum_, 0, &m_sa);
386}

References m_sa, ASSA::SIGACT, and trace_with_mask.

Member Data Documentation

◆ m_sa

SIGACTION ASSA::SigAction::m_sa
private

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