winop->readset_out->fd_count = winop->writeset_out->fd_count
= winop->exset_out->fd_count = 0;
- evsignal_init(_base);
+ evsig_init(_base);
return (winop);
err:
if (!fd_count) {
/* Windows doesn't like you to call select() with no sockets */
Sleep(timeval_to_ms(tv));
- evsignal_process(base);
+ evsig_process(base);
return (0);
}
event_debug(("%s: select returned %d", __func__, res));
if(res <= 0) {
- evsignal_process(base);
+ evsig_process(base);
return res;
- } else if (base->sig.evsignal_caught) {
- evsignal_process(base);
+ } else if (base->sig.evsig_caught) {
+ evsig_process(base);
}
for (i=0; i<win32op->readset_out->fd_count; ++i) {
{
struct win32op *win32op = _base->evbase;
- evsignal_dealloc(_base);
+ evsig_dealloc(_base);
if (win32op->readset_in)
mm_free(win32op->readset_in);
if (win32op->writeset_in)
return (NULL);
}
- evsignal_init(base);
+ evsig_init(base);
return (devpollop);
}
return (-1);
}
- evsignal_process(base);
+ evsig_process(base);
return (0);
- } else if (base->sig.evsignal_caught) {
- evsignal_process(base);
+ } else if (base->sig.evsig_caught) {
+ evsig_process(base);
}
event_debug(("%s: devpoll_wait reports %d", __func__, res));
{
struct devpollop *devpollop = base->evbase;
- evsignal_dealloc(base);
+ evsig_dealloc(base);
if (devpollop->events)
mm_free(devpollop->events);
if (devpollop->changes)
}
epollop->nevents = nfiles;
- evsignal_init(base);
+ evsig_init(base);
return (epollop);
}
return (-1);
}
- evsignal_process(base);
+ evsig_process(base);
return (0);
- } else if (base->sig.evsignal_caught) {
- evsignal_process(base);
+ } else if (base->sig.evsig_caught) {
+ evsig_process(base);
}
event_debug(("%s: epoll_wait reports %d", __func__, res));
{
struct epollop *epollop = base->evbase;
- evsignal_dealloc(base);
+ evsig_dealloc(base);
if (epollop->events)
mm_free(epollop->events);
if (epollop->epfd >= 0)
const struct eventop *evsigsel;
void *evsigbase;
- struct evsignal_info sig;
+ struct evsig_info sig;
int event_count; /* counts number of total events */
int event_count_active; /* counts number of active events */
} while (0)
#endif /* TAILQ_FOREACH */
-int _evsignal_set_handler(struct event_base *base, int evsignal,
+int _evsig_set_handler(struct event_base *base, int evsignal,
void (*fn)(int));
-int _evsignal_restore_handler(struct event_base *base, int evsignal);
+int _evsig_restore_handler(struct event_base *base, int evsignal);
#ifdef __cplusplus
}
/* Global state */
struct event_base *current_base = NULL;
-extern struct event_base *evsignal_base;
+extern struct event_base *evsig_base;
static int use_monotonic;
/* Handle signals - This is a deprecated interface */
base->tv_cache.tv_sec = 0;
if (base->sig.ev_signal_added)
- evsignal_base = base;
+ evsig_base = base;
done = 0;
while (!done) {
/* Terminate the loop if we have been asked to */
for (i = 0; i < EVENTS_PER_GETN; i++)
evpd->ed_pending[i] = -1;
- evsignal_init(base);
+ evsig_init(base);
return (evpd);
}
if ((res = port_getn(epdp->ed_port, pevtlist, EVENTS_PER_GETN,
(unsigned int *) &nevents, ts_p)) == -1) {
if (errno == EINTR || errno == EAGAIN) {
- evsignal_process(base);
+ evsig_process(base);
return (0);
} else if (errno == ETIME) {
if (nevents == 0)
event_warn("port_getn");
return (-1);
}
- } else if (base->sig.evsignal_caught) {
- evsignal_process(base);
+ } else if (base->sig.evsig_caught) {
+ evsig_process(base);
}
event_debug(("%s: port_getn reports %d events", __func__, nevents));
{
struct evport_data *evpd = base->evbase;
- evsignal_dealloc(base);
+ evsig_dealloc(base);
close(evpd->ed_port);
typedef void (*ev_sighandler_t)(int);
-struct evsignal_info {
+struct evsig_info {
struct event ev_signal;
evutil_socket_t ev_signal_pair[2];
int ev_signal_added;
- volatile sig_atomic_t evsignal_caught;
+ volatile sig_atomic_t evsig_caught;
sig_atomic_t evsigcaught[NSIG];
#ifdef HAVE_SIGACTION
struct sigaction **sh_old;
#endif
int sh_old_max;
};
-void evsignal_init(struct event_base *);
-void evsignal_process(struct event_base *);
-void evsignal_dealloc(struct event_base *);
+void evsig_init(struct event_base *);
+void evsig_process(struct event_base *);
+void evsig_dealloc(struct event_base *);
#endif /* _EVSIGNAL_H_ */
#define evtimer_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv)
#define evtimer_initialized(ev) _event_initialized((ev), 0)
-#define signal_add(ev, tv) event_add(ev, tv)
-#define signal_set(ev, x, cb, arg) \
+#define evsignal_add(ev, tv) event_add(ev, tv)
+#define evsignal_set(ev, x, cb, arg) \
event_set(ev, x, EV_SIGNAL|EV_PERSIST, cb, arg)
-#define signal_assign(ev, b, x, cb, arg) \
+#define evsignal_assign(ev, b, x, cb, arg) \
event_assign(ev, b, x, EV_SIGNAL|EV_PERSIST, cb, arg)
-#define signal_new(b, x, cb, arg) \
+#define evsignal_new(b, x, cb, arg) \
event_new(b, x, EV_SIGNAL|EV_PERSIST, cb, arg)
-#define signal_del(ev) event_del(ev)
-#define signal_pending(ev, tv) event_pending(ev, EV_SIGNAL, tv)
-#define signal_initialized(ev) _event_initialized((ev), 0)
+#define evsignal_del(ev) event_del(ev)
+#define evsignal_pending(ev, tv) event_pending(ev, EV_SIGNAL, tv)
+#define evsignal_initialized(ev) _event_initialized((ev), 0)
/**
Prepare an event structure to be added.
#define timeout_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv)
#define timeout_initialized(ev) _event_initialized((ev), 0)
+#define signal_add(ev, tv) event_add(ev, tv)
+#define signal_set(ev, x, cb, arg) \
+ event_set(ev, x, EV_SIGNAL|EV_PERSIST, cb, arg)
+#define signal_assign(ev, b, x, cb, arg) \
+ event_assign(ev, b, x, EV_SIGNAL|EV_PERSIST, cb, arg)
+#define signal_new(b, x, cb, arg) \
+ event_new(b, x, EV_SIGNAL|EV_PERSIST, cb, arg)
+#define signal_del(ev) event_del(ev)
+#define signal_pending(ev, tv) event_pending(ev, EV_SIGNAL, tv)
+#define signal_initialized(ev) _event_initialized((ev), 0)
+
#ifdef __cplusplus
}
#endif
if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1)
return (-1);
- if (_evsignal_set_handler(base, nsignal, kq_sighandler) == -1)
+ if (_evsig_set_handler(base, nsignal, kq_sighandler) == -1)
return (-1);
return (0);
if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1)
return (-1);
- if (_evsignal_restore_handler(base, nsignal) == -1)
+ if (_evsig_restore_handler(base, nsignal) == -1)
return (-1);
return (0);
if (!(pollop = mm_calloc(1, sizeof(struct pollop))))
return (NULL);
- evsignal_init(base);
+ evsig_init(base);
return (pollop);
}
return (-1);
}
- evsignal_process(base);
+ evsig_process(base);
return (0);
- } else if (base->sig.evsignal_caught) {
- evsignal_process(base);
+ } else if (base->sig.evsig_caught) {
+ evsig_process(base);
}
event_debug(("%s: poll reports %d", __func__, res));
{
struct pollop *pop = base->evbase;
- evsignal_dealloc(base);
+ evsig_dealloc(base);
if (pop->event_set)
mm_free(pop->event_set);
if (pop->idxplus1_by_fd)
select_resize(sop, howmany(32 + 1, NFDBITS)*sizeof(fd_mask));
- evsignal_init(base);
+ evsig_init(base);
return (sop);
}
return (-1);
}
- evsignal_process(base);
+ evsig_process(base);
return (0);
- } else if (base->sig.evsignal_caught) {
- evsignal_process(base);
+ } else if (base->sig.evsig_caught) {
+ evsig_process(base);
}
event_debug(("%s: select reports %d", __func__, res));
{
struct selectop *sop = base->evbase;
- evsignal_dealloc(base);
+ evsig_dealloc(base);
if (sop->event_readset_in)
mm_free(sop->event_readset_in);
if (sop->event_writeset_in)
#include "log.h"
#include "evmap.h"
-static int evsignal_add(struct event_base *, int, short, short);
-static int evsignal_del(struct event_base *, int, short, short);
+static int evsig_add(struct event_base *, int, short, short);
+static int evsig_del(struct event_base *, int, short, short);
static const struct eventop evsigops = {
"signal",
NULL,
- evsignal_add,
- evsignal_del,
+ evsig_add,
+ evsig_del,
NULL,
NULL,
0, 0
};
-struct event_base *evsignal_base = NULL;
+struct event_base *evsig_base = NULL;
-static void evsignal_handler(int sig);
+static void evsig_handler(int sig);
/* Callback for when the signal handler write a byte to our signaling socket */
static void
-evsignal_cb(evutil_socket_t fd, short what, void *arg)
+evsig_cb(evutil_socket_t fd, short what, void *arg)
{
static char signals[100];
#ifdef WIN32
#endif
void
-evsignal_init(struct event_base *base)
+evsig_init(struct event_base *base)
{
/*
* Our signal handler is going to write to one end of the socket
FD_CLOSEONEXEC(base->sig.ev_signal_pair[1]);
base->sig.sh_old = NULL;
base->sig.sh_old_max = 0;
- base->sig.evsignal_caught = 0;
+ base->sig.evsig_caught = 0;
memset(&base->sig.evsigcaught, 0, sizeof(sig_atomic_t)*NSIG);
evutil_make_socket_nonblocking(base->sig.ev_signal_pair[0]);
event_assign(&base->sig.ev_signal, base, base->sig.ev_signal_pair[1],
- EV_READ | EV_PERSIST, evsignal_cb, &base->sig.ev_signal);
+ EV_READ | EV_PERSIST, evsig_cb, &base->sig.ev_signal);
base->sig.ev_signal.ev_flags |= EVLIST_INTERNAL;
/* Helper: set the signal handler for evsignal to handler in base, so that
* we can restore the original handler when we clear the current one. */
int
-_evsignal_set_handler(struct event_base *base,
+_evsig_set_handler(struct event_base *base,
int evsignal, void (*handler)(int))
{
#ifdef HAVE_SIGACTION
#else
ev_sighandler_t sh;
#endif
- struct evsignal_info *sig = &base->sig;
+ struct evsig_info *sig = &base->sig;
void *p;
/*
}
static int
-evsignal_add(struct event_base *base, int evsignal, short old, short events)
+evsig_add(struct event_base *base, int evsignal, short old, short events)
{
- struct evsignal_info *sig = &base->sig;
+ struct evsig_info *sig = &base->sig;
assert(evsignal >= 0 && evsignal < NSIG);
event_debug(("%s: %p: changing signal handler", __func__, ev));
- if (_evsignal_set_handler(base, evsignal, evsignal_handler) == -1)
+ if (_evsig_set_handler(base, evsignal, evsig_handler) == -1)
return (-1);
/* catch signals if they happen quickly */
- evsignal_base = base;
+ evsig_base = base;
if (!sig->ev_signal_added) {
if (event_add(&sig->ev_signal, NULL))
}
int
-_evsignal_restore_handler(struct event_base *base, int evsignal)
+_evsig_restore_handler(struct event_base *base, int evsignal)
{
int ret = 0;
- struct evsignal_info *sig = &base->sig;
+ struct evsig_info *sig = &base->sig;
#ifdef HAVE_SIGACTION
struct sigaction *sh;
#else
}
static int
-evsignal_del(struct event_base *base, int evsignal, short old, short events)
+evsig_del(struct event_base *base, int evsignal, short old, short events)
{
assert(evsignal >= 0 && evsignal < NSIG);
event_debug(("%s: %p: restoring signal handler", __func__, ev));
- return (_evsignal_restore_handler(base, evsignal));
+ return (_evsig_restore_handler(base, evsignal));
}
static void
-evsignal_handler(int sig)
+evsig_handler(int sig)
{
int save_errno = errno;
#ifdef WIN32
int socket_errno = EVUTIL_SOCKET_ERROR();
#endif
- if (evsignal_base == NULL) {
+ if (evsig_base == NULL) {
event_warn(
"%s: received signal %d, but have no base configured",
__func__, sig);
return;
}
- evsignal_base->sig.evsigcaught[sig]++;
- evsignal_base->sig.evsignal_caught = 1;
+ evsig_base->sig.evsigcaught[sig]++;
+ evsig_base->sig.evsig_caught = 1;
#ifndef HAVE_SIGACTION
- signal(sig, evsignal_handler);
+ signal(sig, evsig_handler);
#endif
/* Wake up our notification mechanism */
- send(evsignal_base->sig.ev_signal_pair[0], "a", 1, 0);
+ send(evsig_base->sig.ev_signal_pair[0], "a", 1, 0);
errno = save_errno;
#ifdef WIN32
EVUTIL_SET_SOCKET_ERROR(socket_errno);
}
void
-evsignal_process(struct event_base *base)
+evsig_process(struct event_base *base)
{
- struct evsignal_info *sig = &base->sig;
+ struct evsig_info *sig = &base->sig;
sig_atomic_t ncalls;
int i;
- base->sig.evsignal_caught = 0;
+ base->sig.evsig_caught = 0;
for (i = 1; i < NSIG; ++i) {
ncalls = sig->evsigcaught[i];
if (ncalls == 0)
}
void
-evsignal_dealloc(struct event_base *base)
+evsig_dealloc(struct event_base *base)
{
int i = 0;
if (base->sig.ev_signal_added) {
}
for (i = 0; i < NSIG; ++i) {
if (i < base->sig.sh_old_max && base->sig.sh_old[i] != NULL)
- _evsignal_restore_handler(base, i);
+ _evsig_restore_handler(base, i);
}
EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]);
base->sig.ev_signal_pair[1] = -1;
base->sig.sh_old_max = 0;
- /* per index frees are handled in evsignal_del() */
+ /* per index frees are handled in evsig_del() */
mm_free(base->sig.sh_old);
}
if (event_add(&ev, NULL) == -1)
exit(1);
- signal_set(&sig_ev, SIGCHLD, child_signal_cb, &got_sigchld);
- signal_add(&sig_ev, NULL);
+ evsignal_set(&sig_ev, SIGCHLD, child_signal_cb, &got_sigchld);
+ evsignal_add(&sig_ev, NULL);
if ((pid = fork()) == 0) {
/* in the child */
exit(1);
}
- signal_del(&sig_ev);
+ evsignal_del(&sig_ev);
called = 0;
exit(1);
}
- signal_del(&sig_ev);
+ evsignal_del(&sig_ev);
cleanup_test();
}
{
struct event *ev = arg;
- signal_del(ev);
+ evsignal_del(ev);
test_ok = 1;
}
struct itimerval itv;
setup_test("Simple signal: ");
- signal_set(&ev, SIGALRM, signal_cb, &ev);
- signal_add(&ev, NULL);
+ evsignal_set(&ev, SIGALRM, signal_cb, &ev);
+ evsignal_add(&ev, NULL);
/* find bugs in which operations are re-ordered */
- signal_del(&ev);
- signal_add(&ev, NULL);
+ evsignal_del(&ev);
+ evsignal_add(&ev, NULL);
memset(&itv, 0, sizeof(itv));
itv.it_value.tv_sec = 1;
event_dispatch();
skip_simplesignal:
- if (signal_del(&ev) == -1)
+ if (evsignal_del(&ev) == -1)
test_ok = 0;
cleanup_test();
setup_test("Multiple signal: ");
- signal_set(&ev_one, SIGALRM, signal_cb, &ev_one);
- signal_add(&ev_one, NULL);
+ evsignal_set(&ev_one, SIGALRM, signal_cb, &ev_one);
+ evsignal_add(&ev_one, NULL);
- signal_set(&ev_two, SIGALRM, signal_cb, &ev_two);
- signal_add(&ev_two, NULL);
+ evsignal_set(&ev_two, SIGALRM, signal_cb, &ev_two);
+ evsignal_add(&ev_two, NULL);
memset(&itv, 0, sizeof(itv));
itv.it_value.tv_sec = 1;
event_dispatch();
skip_simplesignal:
- if (signal_del(&ev_one) == -1)
+ if (evsignal_del(&ev_one) == -1)
test_ok = 0;
- if (signal_del(&ev_two) == -1)
+ if (evsignal_del(&ev_two) == -1)
test_ok = 0;
cleanup_test();
test_ok = 0;
printf("Immediate signal: ");
- signal_set(&ev, SIGUSR1, signal_cb, &ev);
- signal_add(&ev, NULL);
+ evsignal_set(&ev, SIGUSR1, signal_cb, &ev);
+ evsignal_add(&ev, NULL);
raise(SIGUSR1);
event_loop(EVLOOP_NONBLOCK);
- signal_del(&ev);
+ evsignal_del(&ev);
cleanup_test();
}
static void
test_signal_dealloc(void)
{
- /* make sure that signal_event is event_del'ed and pipe closed */
+ /* make sure that evsignal_event is event_del'ed and pipe closed */
struct event ev;
struct event_base *base = event_init();
printf("Signal dealloc: ");
- signal_set(&ev, SIGUSR1, signal_cb, &ev);
- signal_add(&ev, NULL);
- signal_del(&ev);
+ evsignal_set(&ev, SIGUSR1, signal_cb, &ev);
+ evsignal_add(&ev, NULL);
+ evsignal_del(&ev);
event_base_free(base);
/* If we got here without asserting, we're fine. */
test_ok = 1;
base1 = event_init();
base2 = event_init();
is_kqueue = !strcmp(event_get_method(),"kqueue");
- signal_set(&ev1, SIGUSR1, signal_cb, &ev1);
- signal_set(&ev2, SIGUSR1, signal_cb, &ev2);
+ evsignal_set(&ev1, SIGUSR1, signal_cb, &ev1);
+ evsignal_set(&ev2, SIGUSR1, signal_cb, &ev2);
if (event_base_set(base1, &ev1) ||
event_base_set(base2, &ev2) ||
event_add(&ev1, NULL) ||
test_ok = 0;
printf("Signal handler assert: ");
/* use SIGCONT so we don't kill ourselves when we signal to nowhere */
- signal_set(&ev, SIGCONT, signal_cb, &ev);
- signal_add(&ev, NULL);
+ evsignal_set(&ev, SIGCONT, signal_cb, &ev);
+ evsignal_add(&ev, NULL);
/*
- * if signal_del() fails to reset the handler, it's current handler
- * will still point to evsignal_handler().
+ * if evsignal_del() fails to reset the handler, it's current handler
+ * will still point to evsig_handler().
*/
- signal_del(&ev);
+ evsignal_del(&ev);
raise(SIGCONT);
- /* only way to verify we were in evsignal_handler() */
- if (base->sig.evsignal_caught)
+ /* only way to verify we were in evsig_handler() */
+ if (base->sig.evsig_caught)
test_ok = 0;
else
test_ok = 1;
if (signal(SIGUSR1, signal_cb_sa) == SIG_ERR)
goto out;
#endif
- signal_set(&ev, SIGUSR1, signal_cb, &ev);
- signal_add(&ev, NULL);
- signal_del(&ev);
+ evsignal_set(&ev, SIGUSR1, signal_cb, &ev);
+ evsignal_add(&ev, NULL);
+ evsignal_del(&ev);
raise(SIGUSR1);
/* 1 == signal_cb, 2 == signal_cb_sa, we want our previous handler */