svn commit: samba r22968 - in branches/SAMBA_4_0/source/lib/events: .

tridge at samba.org tridge at samba.org
Thu May 17 07:52:34 GMT 2007


Author: tridge
Date: 2007-05-17 07:52:33 +0000 (Thu, 17 May 2007)
New Revision: 22968

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=22968

Log:

andrew bartlett pointed out that the parent process could add a fd to
the epoll context which would then appear in the children. To fix this
we need to check for pid changes in more places. Luckily on platforms
where we have epoll(), getpid() is very very cheap.

Modified:
   branches/SAMBA_4_0/source/lib/events/events_aio.c
   branches/SAMBA_4_0/source/lib/events/events_epoll.c
   branches/SAMBA_4_0/source/lib/events/events_standard.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/events/events_aio.c
===================================================================
--- branches/SAMBA_4_0/source/lib/events/events_aio.c	2007-05-17 05:46:45 UTC (rev 22967)
+++ branches/SAMBA_4_0/source/lib/events/events_aio.c	2007-05-17 07:52:33 UTC (rev 22968)
@@ -103,10 +103,14 @@
   see http://junkcode.samba.org/ftp/unpacked/junkcode/epoll_fork.c for an 
   demonstration of why this is needed
  */
-static void epoll_reopen(struct aio_event_context *aio_ev)
+static void epoll_check_reopen(struct aio_event_context *aio_ev)
 {
 	struct fd_event *fde;
 
+	if (aio_ev->pid == getpid()) {
+		return;
+	}
+
 	close(aio_ev->epoll_fd);
 	aio_ev->epoll_fd = epoll_create(MAX_AIO_QUEUE_DEPTH);
 	if (aio_ev->epoll_fd == -1) {
@@ -131,16 +135,6 @@
 	struct epoll_event event;
 	if (aio_ev->epoll_fd == -1) return;
 
-	/* during an add event we need to check if our pid has changed
-	   and re-open the epoll socket. Note that we don't need to do this 
-	   for other epoll changes */
-	if (aio_ev->pid != getpid()) {
-		epoll_reopen(aio_ev);
-		/* the current event gets added in epoll_reopen(), so
-		   we can return here */
-		return;
-	}
-
 	fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
 
 	/* if we don't want events yet, don't add an aio_event */
@@ -424,6 +418,8 @@
 							   struct aio_event_context);
 	struct fd_event *fde;
 
+	epoll_check_reopen(aio_ev);
+
 	fde = talloc(mem_ctx?mem_ctx:ev, struct fd_event);
 	if (!fde) return NULL;
 
@@ -468,6 +464,8 @@
 
 	fde->flags = flags;
 
+	epoll_check_reopen(aio_ev);
+
 	epoll_change_event(aio_ev, fde);
 }
 
@@ -485,6 +483,8 @@
 		return 0;
 	}
 
+	epoll_check_reopen(aio_ev);
+
 	return aio_event_loop(aio_ev, &tval);
 }
 

Modified: branches/SAMBA_4_0/source/lib/events/events_epoll.c
===================================================================
--- branches/SAMBA_4_0/source/lib/events/events_epoll.c	2007-05-17 05:46:45 UTC (rev 22967)
+++ branches/SAMBA_4_0/source/lib/events/events_epoll.c	2007-05-17 07:52:33 UTC (rev 22968)
@@ -102,10 +102,14 @@
   see http://junkcode.samba.org/ftp/unpacked/junkcode/epoll_fork.c for an 
   demonstration of why this is needed
  */
-static void epoll_reopen(struct epoll_event_context *epoll_ev)
+static void epoll_check_reopen(struct epoll_event_context *epoll_ev)
 {
 	struct fd_event *fde;
 
+	if (epoll_ev->pid == getpid()) {
+		return;
+	}
+
 	close(epoll_ev->epoll_fd);
 	epoll_ev->epoll_fd = epoll_create(64);
 	if (epoll_ev->epoll_fd == -1) {
@@ -131,16 +135,6 @@
 
 	if (epoll_ev->epoll_fd == -1) return;
 
-	/* during an add event we need to check if our pid has changed
-	   and re-open the epoll socket. Note that we don't need to do this 
-	   for other epoll changes */
-	if (epoll_ev->pid != getpid()) {
-		epoll_reopen(epoll_ev);
-		/* the current event gets added in epoll_reopen(), so
-		   we can return here */
-		return;
-	}
-
 	fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
 
 	/* if we don't want events yet, don't add an epoll_event */
@@ -373,6 +367,8 @@
 							   struct epoll_event_context);
 	struct fd_event *fde;
 
+	epoll_check_reopen(epoll_ev);
+
 	fde = talloc(mem_ctx?mem_ctx:ev, struct fd_event);
 	if (!fde) return NULL;
 
@@ -417,6 +413,8 @@
 
 	fde->flags = flags;
 
+	epoll_check_reopen(epoll_ev);
+
 	epoll_change_event(epoll_ev, fde);
 }
 
@@ -434,6 +432,8 @@
 		return 0;
 	}
 
+	epoll_check_reopen(epoll_ev);
+
 	return epoll_event_loop(epoll_ev, &tval);
 }
 

Modified: branches/SAMBA_4_0/source/lib/events/events_standard.c
===================================================================
--- branches/SAMBA_4_0/source/lib/events/events_standard.c	2007-05-17 05:46:45 UTC (rev 22967)
+++ branches/SAMBA_4_0/source/lib/events/events_standard.c	2007-05-17 07:52:33 UTC (rev 22968)
@@ -119,10 +119,14 @@
   see http://junkcode.samba.org/ftp/unpacked/junkcode/epoll_fork.c for an 
   demonstration of why this is needed
  */
-static void epoll_reopen(struct std_event_context *std_ev)
+static void epoll_check_reopen(struct std_event_context *std_ev)
 {
 	struct fd_event *fde;
 
+	if (std_ev->pid == getpid()) {
+		return;
+	}
+
 	close(std_ev->epoll_fd);
 	std_ev->epoll_fd = epoll_create(64);
 	if (std_ev->epoll_fd == -1) {
@@ -147,16 +151,6 @@
 	struct epoll_event event;
 	if (std_ev->epoll_fd == -1) return;
 
-	/* during an add event we need to check if our pid has changed
-	   and re-open the epoll socket. Note that we don't need to do this 
-	   for other epoll changes */
-	if (std_ev->pid != getpid()) {
-		epoll_reopen(std_ev);
-		/* the current event gets added in epoll_reopen(), so
-		   we can return here */
-		return;
-	}
-
 	fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR;
 
 	/* if we don't want events yet, don't add an epoll_event */
@@ -415,6 +409,8 @@
 							   struct std_event_context);
 	struct fd_event *fde;
 
+	epoll_check_reopen(std_ev);
+
 	fde = talloc(mem_ctx?mem_ctx:ev, struct fd_event);
 	if (!fde) return NULL;
 
@@ -462,6 +458,8 @@
 
 	fde->flags = flags;
 
+	epoll_check_reopen(std_ev);
+
 	epoll_change_event(std_ev, fde);
 }
 
@@ -558,6 +556,8 @@
 		return 0;
 	}
 
+	epoll_check_reopen(std_ev);
+
 	if (epoll_event_loop(std_ev, &tval) == 0) {
 		return 0;
 	}



More information about the samba-cvs mailing list