Back to index

im-sdk  12.3.91
Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
IMSignal Class Reference

#include <IMSignal.hh>

Collaboration diagram for IMSignal:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static IMSignalget_instance ()
static IMSignalconstruct (IMSvr *pimsvr)
static void cleanup ()

Private Member Functions

RETSIGTYPE sighup ()
RETSIGTYPE term ()
RETSIGTYPE segv ()
RETSIGTYPE abrt ()
RETSIGTYPE trap ()
RETSIGTYPE fpe ()
RETSIGTYPE bus ()
RETSIGTYPE _segv (int num)
IMSignal_handler getfunc (int)
void add (int signum, IMSignal_handler h)
void ignore (int signum)
 IMSignal (IMSvr *pimsvr)

Private Attributes

IMSvrpsvr
IMSignalHandlerMap hmap

Static Private Attributes

static IMSignalpsinst = NULL

Friends

void signal_handler (int)

Detailed Description

Definition at line 19 of file IMSignal.hh.


Constructor & Destructor Documentation

IMSignal::IMSignal ( IMSvr pimsvr) [private]

Definition at line 182 of file IMSignal.cpp.

  : psvr(pimsvr)
{
    add(SIGHUP, &IMSignal::sighup);
    add(SIGINT, &IMSignal::term);
    add(SIGSEGV, &IMSignal::segv);
    add(SIGABRT, &IMSignal::abrt);
    add(SIGTRAP, &IMSignal::trap);
    add(SIGFPE, &IMSignal::fpe);
    add(SIGBUS, &IMSignal::bus);
    ignore(SIGPIPE);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

RETSIGTYPE IMSignal::_segv ( int  num) [private]

Definition at line 62 of file IMSignal.cpp.

{
    static int in_segv = 0;
    pid_t pid;
    stringstream s;
    string spid, signum;

    s << getpid();
    spid = s.str();
    s.str("");
    s << num;
    signum = s.str();

    in_segv++;

    if (in_segv > 1) {
       /* avoid the multiple segfaulting */
       LOG_CRITICAL("Multiple crashes have occurred.  Give up to storing logs.");
       _exit(255);
    }

    pid = fork();
    if (pid < 0) {
       LOG_CRITICAL("Crash has occurred.  Unable to store logs.");
       _exit(255);
    } else if (pid > 0) {
       /* parent */
       int status;
       pid_t retval;

       retval = waitpid(pid, &status, 0);
       LOG_CRITICAL("Crash has occurred.  Please see /var/log/iiim/ or $HOME/.iiim/logs/ for details.");
       _exit(255);
    } else {
       /* child */
       int retval;

       retval = execl(SEGVLOGGER,
                     SEGVLOGGER,
                     spid.c_str(), signum.c_str(), NULL);
       if (retval == -1)
           LOG_CRITICAL("Unable to run logger program `%s'.", SEGVLOGGER);
       _exit(99);
    }

    in_segv--;
}

Here is the caller graph for this function:

RETSIGTYPE IMSignal::abrt ( ) [private]

Definition at line 38 of file IMSignal.cpp.

{
    _segv(SIGABRT);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void IMSignal::add ( int  signum,
IMSignal_handler  h 
) [private]

Definition at line 143 of file IMSignal.cpp.

{
    hmap[num] = h;
#ifdef HAVE_SIGACTION
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = signal_handler;
    sa.sa_flags = SA_NOCLDSTOP;
#ifdef SA_RESTART
    sa.sa_flags |= SA_RESTART;
#endif
    ::sigaction(num, &sa, NULL);
#elif defined(HAVE_SIGNAL)
    ::signal(num, signal_handler);
#endif
}

Here is the caller graph for this function:

RETSIGTYPE IMSignal::bus ( ) [private]

Definition at line 56 of file IMSignal.cpp.

{
    _segv(SIGBUS);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void IMSignal::cleanup ( ) [inline, static]

Definition at line 52 of file IMSignal.hh.

    {
       if (psinst) delete psinst;
       psinst = NULL;
    }

Here is the caller graph for this function:

IMSignal * IMSignal::construct ( IMSvr pimsvr) [static]

Definition at line 197 of file IMSignal.cpp.

{
    if (psinst) return psinst;
    psinst = new IMSignal(pimsvr);

    return psinst;
}

Here is the call graph for this function:

Here is the caller graph for this function:

RETSIGTYPE IMSignal::fpe ( ) [private]

Definition at line 50 of file IMSignal.cpp.

{
    _segv(SIGFPE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static IMSignal* IMSignal::get_instance ( ) [inline, static]

Definition at line 47 of file IMSignal.hh.

    { return psinst; }

Here is the caller graph for this function:

IMSignal_handler IMSignal::getfunc ( int  num) [private]

Definition at line 130 of file IMSignal.cpp.

{
    IMSignalHandlerMap::iterator i;

    i = hmap.find(num);
    if (i == hmap.end()) return NULL;

    return i->second;
}

Here is the caller graph for this function:

void IMSignal::ignore ( int  signum) [private]

Definition at line 164 of file IMSignal.cpp.

{
    hmap[num] = NULL;
#ifdef HAVE_SIGACTION
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = SIG_IGN;
#ifdef SA_RESTART
    sa.sa_flags = SA_RESTART;
#endif
    ::sigaction(num, &sa, NULL);
#elif defined(HAVE_SIGNAL)
    ::signal(num, SIG_IGN);
#endif
}

Here is the caller graph for this function:

RETSIGTYPE IMSignal::segv ( ) [private]

Definition at line 32 of file IMSignal.cpp.

{
    _segv(SIGSEGV);
}

Here is the call graph for this function:

Here is the caller graph for this function:

RETSIGTYPE IMSignal::sighup ( ) [private]

Definition at line 20 of file IMSignal.cpp.

{
    psvr->reload();
}

Here is the call graph for this function:

Here is the caller graph for this function:

RETSIGTYPE IMSignal::term ( ) [private]

Definition at line 26 of file IMSignal.cpp.

{
    psvr->terminate();
}

Here is the call graph for this function:

Here is the caller graph for this function:

RETSIGTYPE IMSignal::trap ( ) [private]

Definition at line 44 of file IMSignal.cpp.

{
    _segv(SIGTRAP);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

void signal_handler ( int  ) [friend]

Definition at line 115 of file IMSignal.cpp.

{
    IMSignal *pims = IMSignal::get_instance();
    IMSignal_handler ph;

    if (!pims) return;
    ph = pims->getfunc(num);
    if (!ph) return;
    (pims->*ph)();
    return;
}

Member Data Documentation

Definition at line 23 of file IMSignal.hh.

IMSignal * IMSignal::psinst = NULL [static, private]

Definition at line 21 of file IMSignal.hh.

IMSvr* IMSignal::psvr [private]

Definition at line 22 of file IMSignal.hh.


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