[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] Signalar handlers installed but not invoked?
- To: libevent-users@xxxxxxxx
- Subject: [Libevent-users] Signalar handlers installed but not invoked?
- From: Jeffrey Walton <noloader@xxxxxxxxx>
- Date: Tue, 25 Feb 2014 20:37:08 -0500
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Tue, 25 Feb 2014 20:37:13 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:date:message-id:subject:from:to:content-type; bh=JtAEydpd3TTlLVt5shbD5/zKBC/kVOh1EHPtDjlry4g=; b=ptJ3w/rqrZFbM/OlxP188nH+9WoD5PmQEII28oeJRvJ3OdnJAQllya5/jEAIb1d4RG QaWCZ4QDe77+gfFNwiUNXXFDnDSqDoVTv8GXmkysmBXrwvH6MloYMpOdaGqO8TyAHB16 RvVZ80AbD8sI+KSqBDc/+sjqaMC++17ePQe1fGMntxtduUN4bNYnhzh/kIUGdjpYUWa2 HR2zuTgT+D84Aoe6qXSF5YNvWreMjyYJjqBbwhbuqv8PKxoEbsW3yumyeFMM4wSElqlv Rs0q6QZIAHkh3MOlllUsbLBS9y6KoksOcUfPn2wz/0HkvCO+q9qGfYyNCdRE3JVkSY1G MS3g==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
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 majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.