Loading...
Searching...
No Matches
SigAction.h
Go to the documentation of this file.
// -*- c++ -*-
//------------------------------------------------------------------------------
// SigAction.h
//------------------------------------------------------------------------------
// Copyright (c) 1997 by Vladislav Grinchenko
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//------------------------------------------------------------------------------
#ifndef _SigAction_h
#define _SigAction_h
// System includes
//
#include <signal.h>
#include <errno.h>
#include "assa/Assure.h"
#include "assa/SigSet.h"
// some convenient typedefs
//
extern "C" {
typedef struct sigaction SIGACTION;
typedef void (*C_SIG_HANDLER)( int );
}
namespace ASSA {
#if !defined(WIN32)
class SigAction
{
public:
SigAction();
SigAction (C_SIG_HANDLER handler_,
SigSet* sig_mask_ = 0,
int flags_ = 0);
SigAction (C_SIG_HANDLER handler_,
int signum_,
SigSet* sig_mask_ = 0,
int flags_ = 0);
int register_action (int signum_, SigAction* oaction_ = 0);
int restore_action (int signum_, SigAction& oaction_);
int retrieve_action (int signum_);
void action (SIGACTION * sa_);
SIGACTION * action ();
void flags (int new_flags_);
int flags ();
void mask (SigSet & mask_set_);
SigSet mask ();
void handler (C_SIG_HANDLER sha_);
C_SIG_HANDLER handler ();
operator SIGACTION *();
private:
SIGACTION m_sa;
};
//-------------------------------------------------------------------------
//------------------------Inline functions---------------------------------
//-------------------------------------------------------------------------
inline
SigAction::
SigAction ()
{
trace_with_mask("SigAction::SigAction", SIGACT);
m_sa.sa_flags = 0;
sigemptyset(&m_sa.sa_mask);
*(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) 0;
}
inline
SigAction::
SigAction (C_SIG_HANDLER handler_,
SigSet* sig_mask_,
int flags_)
{
trace_with_mask("SigAction::SigAction(,,)", SIGACT);
m_sa.sa_flags = flags_;
if (sig_mask_ == NULL) {
sigemptyset(&m_sa.sa_mask);
}
else {
/*---
here, suppose to do bitwise structure assignment,
but does it really do so?
= *sig_mask_
= *(sig_mask_.operator *())
= *(SigSet *tmp = &sig_mask_.m_sa) ????
---*/
m_sa.sa_mask = **sig_mask_;
}
*(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) handler_;
}
inline
SigAction::
SigAction (C_SIG_HANDLER handler_,
int signum_,
SigSet* sig_mask_,
int flags_)
{
trace_with_mask("SigAction::SigAction(,,,)", SIGACT);
m_sa.sa_flags = flags_;
if (sig_mask_ == NULL) {
sigemptyset(&m_sa.sa_mask);
}
else {
/*--- same problem as above... ---*/
m_sa.sa_mask = **sig_mask_;
}
*(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) handler_;
/*--- installing disposition... ---*/
sigaction (signum_, &m_sa, 0);
}
inline void
SigAction::
action (SIGACTION* sa_)
{
trace_with_mask("SigAction::action", SIGACT);
m_sa = *sa_;
}
inline SIGACTION *
SigAction::
action ()
{
trace_with_mask("SigAction::action", SIGACT);
return &m_sa;
}
inline void
SigAction::
flags (int new_flags_)
{
trace_with_mask("void SigAction::flags()", SIGACT);
m_sa.sa_flags = new_flags_;
}
inline int
SigAction::
flags ()
{
trace_with_mask("int SigAction::flags()", SIGACT);
return m_sa.sa_flags;
}
inline void
SigAction::
mask (SigSet & mask_set_)
{
trace_with_mask("void SigAction::mask()", SIGACT);
m_sa.sa_mask = *mask_set_;
}
inline SigSet
SigAction::
mask ()
{
trace_with_mask("SigSet SigAction::mask()", SIGACT);
SigSet tmpset(&m_sa.sa_mask);
return tmpset;
}
inline void
SigAction::
handler (C_SIG_HANDLER sha_)
{
trace_with_mask("void SigAction::handler()", SIGACT);
*(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) sha_;
}
inline C_SIG_HANDLER
SigAction::
handler ()
{
trace_with_mask("C_SIG_HANDLER SigAction::handler()", SIGACT);
return (C_SIG_HANDLER) m_sa.sa_handler;
}
inline
SigAction::operator SIGACTION * ()
{
trace_with_mask("SigAction::operator SIGACTION * ()", SIGACT);
return &m_sa;
}
inline int
SigAction::
register_action (int signum_, SigAction* oaction_)
{
trace_with_mask("SigAction::register_action()", SIGACT);
/*--- place here recursive mutex lock to guard ... ---*/
struct sigaction *osa = oaction_ == 0 ? 0 : oaction_->action();
return sigaction(signum_, &m_sa, osa);
}
inline int
SigAction::
restore_action (int signum_, SigAction& oaction_)
{
trace_with_mask("SigAction::restore_action()", SIGACT);
m_sa = *oaction_.action();
return sigaction(signum_, &m_sa, 0);
}
inline int
SigAction::
retrieve_action (int signum_)
{
trace_with_mask("SigAction::retrieve_action()", SIGACT);
return sigaction(signum_, 0, &m_sa);
}
#endif // !defined(WIN32)
} // end namespace ASSA
#endif /* _SigAction_h */
Assure.h
A collection of assert function wrappers.
trace_with_mask
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
C_SIG_HANDLER
void(* C_SIG_HANDLER)(int)
Definition SigAction.h:28
SIGACTION
struct sigaction SIGACTION
Definition SigAction.h:27
SigSet.h
SigSet is a wrapper for UNIX sigset_t structure that provides all manipulators on this structure as w...
ASSA::AutoPtrRef
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
ASSA::SigAction
Definition SigAction.h:95
ASSA::SigAction::restore_action
int restore_action(int signum_, SigAction &oaction_)
Change object's disposition to oaction_, and install it as current disposition for the signal signum_...
Definition SigAction.h:371
ASSA::SigAction::SigAction
SigAction()
Default constructor creates SigAction object with null-action.
Definition SigAction.h:221
ASSA::SigAction::retrieve_action
int retrieve_action(int signum_)
Retrieve current disposition for the signal signum_ into this object.
Definition SigAction.h:381
ASSA::SigAction::handler
C_SIG_HANDLER handler()
Retrieve current signal handler function.
Definition SigAction.h:343
ASSA::SigAction::mask
SigSet mask()
Retrieve current signal mask.
Definition SigAction.h:324
ASSA::SigAction::m_sa
SIGACTION m_sa
sigaction structure itself
Definition SigAction.h:213
ASSA::SigAction::flags
int flags()
Retrieve current flags.
Definition SigAction.h:306
ASSA::SigAction::register_action
int register_action(int signum_, SigAction *oaction_=0)
Register this object as current disposition for signal signum_, and store old disposition in oaction_...
Definition SigAction.h:360
ASSA::SigAction::action
SIGACTION * action()
Retrieve current sigaction.
Definition SigAction.h:288
ASSA::SigSet
Definition SigSet.h:53
ASSA
Definition Acceptor.h:40
ASSA::SIGACT
@ SIGACT
Class SigACtion messages
Definition LogMask.h:48