]> granicus.if.org Git - libevent/commitdiff
test/regress: main/fork: rewrite assertions by just removing event in callback
authorAzat Khuzhin <a3at.mail@gmail.com>
Sat, 26 Dec 2015 23:31:03 +0000 (02:31 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Sun, 27 Dec 2015 06:28:07 +0000 (09:28 +0300)
Instead of assigning some variable value (got_child), and schedule exit from
loop from that callback, just remove event for that signal, and event loop will
exit automatically when there will be no events.

test/regress.c

index 4d1708202c80032d71a202a7a98e54f84012b2d4..d200ae3571e2ba23d4bf42dfa8faf2ec4215faea 100644 (file)
@@ -817,28 +817,21 @@ end:
 }
 
 #ifndef _WIN32
-static void signal_cb(evutil_socket_t fd, short event, void *arg);
 
 #define current_base event_global_current_base_
 extern struct event_base *current_base;
 
 static void
-child_signal_cb(evutil_socket_t fd, short event, void *arg)
+fork_signal_cb(evutil_socket_t fd, short events, void *arg)
 {
-       struct timeval tv;
-       int *pint = arg;
-
-       *pint = 1;
-
-       tv.tv_usec = 500000;
-       tv.tv_sec = 0;
-       event_loopexit(&tv);
+       event_del(arg);
 }
 
+
 static void
 test_fork(void)
 {
-       int status, got_sigchld = 0;
+       int status;
        struct event ev, sig_ev;
        pid_t pid;
 
@@ -855,7 +848,7 @@ test_fork(void)
        if (event_add(&ev, NULL) == -1)
                exit(1);
 
-       evsignal_set(&sig_ev, SIGCHLD, child_signal_cb, &got_sigchld);
+       evsignal_set(&sig_ev, SIGCHLD, fork_signal_cb, &sig_ev);
        evsignal_add(&sig_ev, NULL);
 
        event_base_assert_ok_(current_base);
@@ -917,11 +910,6 @@ test_fork(void)
 
        event_dispatch();
 
-       if (!got_sigchld) {
-               fprintf(stdout, "FAILED (sigchld)\n");
-               exit(1);
-       }
-
        evsignal_del(&sig_ev);
 
        end: