diff --git a/event.c b/event.c index a5a42234..e7ed5236 100644 --- a/event.c +++ b/event.c @@ -375,8 +375,11 @@ event_reinit(struct event_base *base) return (0); /* prevent internal delete */ - if (base->sig.ev_signal_added) + if (base->sig.ev_signal_added) { + event_queue_remove(base, &base->sig.ev_signal, + EVLIST_INSERTED); base->sig.ev_signal_added = 0; + } if (base->evsel->dealloc != NULL) base->evsel->dealloc(base, base->evbase); diff --git a/test/regress.c b/test/regress.c index f1539f66..a1949864 100644 --- a/test/regress.c +++ b/test/regress.c @@ -482,10 +482,24 @@ test_periodictimeout(void) static void signal_cb(int fd, short event, void *arg); extern struct event_base *current_base; + +static void +child_signal_cb(int fd, short event, void *arg) +{ + struct timeval tv; + int *pint = arg; + + *pint = 1; + + tv.tv_usec = 500000; + tv.tv_sec = 0; + event_loopexit(&tv); +} + static void test_fork(void) { - int status; + int status, got_sigchld = 0; struct event ev, sig_ev; pid_t pid; @@ -497,7 +511,7 @@ test_fork(void) if (event_add(&ev, NULL) == -1) exit(1); - signal_set(&sig_ev, SIGALRM, signal_cb, &ev); + signal_set(&sig_ev, SIGCHLD, child_signal_cb, &got_sigchld); signal_add(&sig_ev, NULL); if ((pid = fork()) == 0) { @@ -524,8 +538,6 @@ test_fork(void) /* wait for the child to read the data */ sleep(1); - signal_del(&sig_ev); - write(pair[0], TEST1, strlen(TEST1)+1); if (waitpid(pid, &status, 0) == -1) { @@ -544,6 +556,13 @@ test_fork(void) event_dispatch(); + if (!got_sigchld) { + fprintf(stdout, "FAILED (sigchld)\n"); + exit(1); + } + + signal_del(&sig_ev); + cleanup_test(); }