]> granicus.if.org Git - libevent/commitdiff
Warn if forked from the event loop during event_reinit()
authorAzat Khuzhin <azat@libevent.org>
Mon, 1 Jul 2019 20:54:02 +0000 (23:54 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Thu, 1 Aug 2019 21:08:41 +0000 (00:08 +0300)
Calling fork() from the event loop is not a great idea, since at least
it shares some internal pipes (for handling signals) before
event_reinit() call

Closes: #833
(cherry picked from commit 497ef904d544ac51de43934549dbeccce8e6e8f8)

event.c

diff --git a/event.c b/event.c
index bfd94ebd05447c7a1837859df1a59eadc62f4f67..b2ad341026a835254f85f8fe7c76f28c4591151c 100644 (file)
--- a/event.c
+++ b/event.c
@@ -987,6 +987,12 @@ event_reinit(struct event_base *base)
 
        EVBASE_ACQUIRE_LOCK(base, th_base_lock);
 
+       if (base->running_loop) {
+               event_warnx("%s: forked from the event_loop.", __func__);
+               res = -1;
+               goto done;
+       }
+
        evsel = base->evsel;
 
        /* check if this event mechanism requires reinit on the backend */