another fix; we also need to remove the signal event from the queue
authorNiels Provos <provos@gmail.com>
Fri, 25 Jul 2008 00:48:30 +0000 (00:48 +0000)
committerNiels Provos <provos@gmail.com>
Fri, 25 Jul 2008 00:48:30 +0000 (00:48 +0000)
svn:r918

event.c
test/regress.c

diff --git a/event.c b/event.c
index a5a4223405a0265765564a9eebbda002c9292516..e7ed52363485fce54aeafa0508bdff4297008abd 100644 (file)
--- 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);
index f1539f66fb01454eeba7936142ff18db374d9b19..a19498640f488725d2c30f29658d7db6d0c63002 100644 (file)
@@ -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();
 }