PERFORCE change 123599 for review

Fredrik Lindberg fli at FreeBSD.org
Mon Jul 16 17:13:08 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=123599

Change 123599 by fli at fli_nexus on 2007/07/16 17:12:47

	Save the original initialization argument from event_add() and
	pass it to remove_event() when we internally in the event system
	remove an event due to EOF errors and the like.
	This is to make sure that event handler initialization functions get
	the corrent arguments on close to allow them to terminate properly.

Affected files ...

.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/event.c#5 edit
.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/event.h#4 edit

Differences ...

==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/event.c#5 (text+ko) ====

@@ -100,7 +100,7 @@
 		ev = TAILQ_FIRST(&evl->evl_events);
 		EV_WLOCK(ev);
 		ev->ev_flags |= EVENT_FLAG_DYING;
-		if (remove_event(evl, ev, NULL) == 1) {
+		if (remove_event(evl, ev, &ev->ev_init_arg) == 1) {
 			EV_UNLOCK(ev);
 		}
 	}
@@ -163,7 +163,7 @@
 	ev->ev_refcnt--;
 	if (ev->ev_flags & EVENT_FLAG_DYING) {
 		evl = ev->ev_evl;
-		if (remove_event(evl, ev, NULL) == 1) {
+		if (remove_event(evl, ev, &ev->ev_init_arg) == 1) {
 			EV_UNLOCK(ev);
 		}
 	}
@@ -219,7 +219,7 @@
 
 		EV_WLOCK(ev);
 		if (kev.flags & EV_EOF) {
-			if (remove_event(evl, ev, NULL) == 1) {
+			if (remove_event(evl, ev, &ev->ev_init_arg) == 1) {
 				EV_UNLOCK(ev);
 			}
 			continue;
@@ -228,7 +228,7 @@
 		/* Event has been removed, delete if nobody is using it */
 		if (ev->ev_flags & EVENT_FLAG_DYING) {
 			if (ev->ev_refcnt == 0)
-				remove_event(evl, ev, NULL);
+				remove_event(evl, ev, &ev->ev_init_arg);
 			else {
 				EV_UNLOCK(ev);
 			}
@@ -301,7 +301,6 @@
 	int ret;
 	struct event *ev;
 	struct evgen *evg;
-	ev_arg ev_arg_init;
 	struct kevent kev;
 
 	MDNS_INIT_ASSERT(evl, evl_magic);
@@ -318,9 +317,9 @@
 		bzero(&ev->ev_handler_arg, sizeof(ev_arg));
 
 	if (init_arg != NULL)
-		memcpy(&ev_arg_init, init_arg, sizeof(ev_arg));
+		memcpy(&ev->ev_init_arg, init_arg, sizeof(ev_arg));
 	else
-		bzero(&ev_arg_init, sizeof(ev_arg));
+		bzero(&ev->ev_init_arg, sizeof(ev_arg));
 		
 	ev->ev_cb.ev_init.ptr = init;
 	ev->ev_type = type;
@@ -337,7 +336,7 @@
 	case EVENT_TYPE_IO:
 		if (init != NULL)
 			ret = ev->ev_cb.ev_init.io(EVENT_INIT_OPEN,
-			    &ev->ev_data.io, ev_arg_init);
+			    &ev->ev_data.io, ev->ev_init_arg);
 		if (ev->ev_data.io.evio_dir == EVENT_IO_READ)
 			kev.filter = EVFILT_READ;
 		else if (ev->ev_data.io.evio_dir == EVENT_IO_WRITE)
@@ -349,7 +348,7 @@
 	case EVENT_TYPE_TMR:
 		if (init != NULL)
 			ret = ev->ev_cb.ev_init.tmr(EVENT_INIT_OPEN,
-			    &ev->ev_data.tmr, ev_arg_init);
+			    &ev->ev_data.tmr, ev->ev_init_arg);
 		kev.filter = EVFILT_TIMER;
 		if (ev->ev_data.tmr.evtmr_oneshot)
 			kev.flags |= EV_ONESHOT;	
@@ -360,7 +359,7 @@
 	case EVENT_TYPE_SIG:
 		if (init != NULL)
 			ret = ev->ev_cb.ev_init.sig(EVENT_INIT_OPEN,
-			    &ev->ev_data.sig, ev_arg_init);
+			    &ev->ev_data.sig, ev->ev_init_arg);
 		kev.filter = EVFILT_SIGNAL;
 		signal(ev->ev_data.sig.evsig_signo, SIG_IGN);
 		kev.ident = ev->ev_data.sig.evsig_signo;
@@ -423,6 +422,13 @@
 	dprintf(DEBUG_EVENT, "Removing event ev=%x", ev);
 
 	if (remove_event(evl, ev, arg) == 1) {
+		/*
+		 * We failed to remove the event because it's in use,
+		 * make sure to save the passed argument so that it is
+		 * properly passed to remove_event() once the event
+		 * can be removed.
+		 */
+		memcpy(&ev->ev_init_arg, arg, sizeof(ev_arg));
 		EV_UNLOCK(ev);
 	}
 

==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/event.h#4 (text+ko) ====

@@ -148,6 +148,7 @@
 		} ev_init;
 	} ev_cb;
 	ev_arg ev_handler_arg; /* Callback argument */
+	ev_arg ev_init_arg; /* Init callback argument */
 
 	/*
 	 * Event type specific data


More information about the p4-projects mailing list