Hello, list

Please consider my application:

1. There is one process that always in event loop (master process).
2. By some event it forks and create "child" process, that call 
event_exit_loop() and after event_loop() exits it try to clean up everything 
associated with libevent.
3. For this purpose child call event_base_free(), but it have to remove all 
events that was added by parent before fork happened. Otherwise it will be 
hit by assert(TAILQ_EMPTY(&base->eventqueue)).
4. With poll or select methods there no problems with deleting events at this 
point.
5. But with epoll, kqueue or event ports methods the child and the parent 
shares *same* event device and set of file descriptors after fork(). So if 
child call event_del() on every event that was added before in parent, events 
are also deleted from parent's device (actually, the same device), which is 
absolutely not what I want.

Thus, there is only one way to deal with it: child must not call 
event_base_free() and must live with opened event device.

Attached diff provides a fix for this situation. I believe process must not 
check if base->eventqueue and other queues are empty. Calling 
evsel->dealloc() is enough to remove all events.



-- 
Andrei Nigmatulin
GPG PUB KEY 6449830D

Now I lay me down to sleep(3)
Pray the OS my core to keep
If I die before I wake
Pray the Disk my core to take
diff -burp libevent/event.c ./event.c
--- libevent/event.c	2007-06-08 01:59:32.000000000 +0400
+++ ./event.c	2007-06-12 15:58:28.000000000 +0400
@@ -220,19 +220,14 @@ event_base_free(struct event_base *base)
 		current_base = NULL;
 
 	assert(base);
+
 	if (base->evsel->dealloc != NULL)
 		base->evsel->dealloc(base, base->evbase);
-	for (i=0; i < base->nactivequeues; ++i)
-		assert(TAILQ_EMPTY(base->activequeues[i]));
-
-	assert(RB_EMPTY(&base->timetree));
 
 	for (i = 0; i < base->nactivequeues; ++i)
 		free(base->activequeues[i]);
 	free(base->activequeues);
 
-	assert(TAILQ_EMPTY(&base->eventqueue));
-
 	free(base);
 }
 
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to