use sigtimedwait for proper sighandler thread shutdown

remotes/origin/2.0
Richard Fuchs 13 years ago
parent 5cecf39605
commit 61ffa69282

@ -7,6 +7,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <errno.h>
#include "poller.h" #include "poller.h"
#include "control.h" #include "control.h"
@ -60,7 +61,8 @@ static char *b2b_url;
gpointer sighandler(gpointer x) { gpointer sighandler(gpointer x) {
sigset_t ss; sigset_t ss;
int ret, sig; int ret;
struct timespec ts;
sigemptyset(&ss); sigemptyset(&ss);
sigaddset(&ss, SIGINT); sigaddset(&ss, SIGINT);
@ -69,12 +71,18 @@ gpointer sighandler(gpointer x) {
sigaddset(&ss, SIGSEGV); sigaddset(&ss, SIGSEGV);
sigaddset(&ss, SIGQUIT); sigaddset(&ss, SIGQUIT);
ts.tv_sec = 0;
ts.tv_nsec = 100000000; /* 0.1 sec */
while (!global_shutdown) { while (!global_shutdown) {
ret = sigwait(&ss, &sig); ret = sigtimedwait(&ss, NULL, &ts);
if (ret) if (ret == -1) {
if (errno == EAGAIN || errno == EINTR)
continue;
abort(); abort();
}
if (sig == SIGINT || sig == SIGTERM) if (ret == SIGINT || ret == SIGTERM)
global_shutdown = 1; global_shutdown = 1;
else else
abort(); abort();

Loading…
Cancel
Save