Discussion:
Signalar handlers installed but not invoked?
(too old to reply)
Jeffrey Walton
2014-02-26 01:37:08 UTC
Permalink
Raw Message
The code below installs a couple of signal handlers. I see info-level
log messages that they were installed (so I know the code is
executed):

Info: installed SIGHUP handler
Info: installed SIGINT handler

When I use `kill` to send a signal, the signal handler is not invoked:

kill -s SIGHUP <pid>


To further complicate issues, the `base` below is the *second* base
used by the progam. The first base is used as part of LibEventInit()
class object that for initialization. Construction creates the base to
initialize the library, and then destroys it at program exit in the
dtor.

Any ideas what I'm doing wrong?

Thanks in advance.

////////////////////
// Base and Signal handler setup
shared_ptr<event_base> base(event_base_new(),
std::ptr_fun(event_base_free));
...

static const int PROGRAM_SIGNALS[] = { SIGHUP, SIGINT };
for (unsigned i = 0; i < COUNTOF(PROGRAM_SIGNALS); i++)
{
const int signum = PROGRAM_SIGNALS[i];
event* sev = evsignal_new(base.get(), signum, signal_cb, (void
* )base.get());

if (sev == NULL) {
// Never encountered
LogError(...);
continue;
}

shared_ptr<event> ptr(sev, std::ptr_fun(event_free));
std_events.push_back(ptr);

LogInfo("installed " + GetSignalName(signum) + " handler");
}

////////////////////
// Signal handler
void signal_cb(evutil_socket_t sig, short events, void *arg)
{
event_base *base = (event_base *) arg;

ostringstream oss;
oss << "signal " << GetSignalName(sig) << ". Exiting in ";
oss << EXIT_SECONDS << " seconds";

static const timeval delay = { EXIT_SECONDS, 0 };
int rc = event_base_loopexit(base, &delay);
if (rc != 0)
LogError("event_base_loopexit failed");
}
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.

Loading...