[SCM] Samba Shared Repository - branch master updated

Simo Sorce idra at samba.org
Thu Aug 11 13:57:02 MDT 2011


The branch, master has been updated
       via  ce93b4f tevent: fix documentation for tevent_context_init_byname()
       via  158b208 tevent: Set FD_CLOEXEC on epoll handle
      from  d52343a s3-messaging: Do not register to classes we are not going to use.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit ce93b4f4645b15e204590633a8047c2bfec13154
Author: Sumit Bose <sbose at redhat.com>
Date:   Thu Aug 11 12:39:57 2011 +0200

    tevent: fix documentation for tevent_context_init_byname()
    
    Signed-off-by: Simo Sorce <idra at samba.org>
    
    Autobuild-User: Simo Sorce <idra at samba.org>
    Autobuild-Date: Thu Aug 11 21:56:37 CEST 2011 on sn-devel-104

commit 158b208dfd75c04698f9f9196161322b16a020a2
Author: Sumit Bose <sbose at redhat.com>
Date:   Thu Aug 11 12:30:48 2011 +0200

    tevent: Set FD_CLOEXEC on epoll handle
    
    If an application using libtevent starts a new process the epoll file descriptor
    is leaked to the new process if the event context is not freed explicitly. By
    setting FD_CLOEXEC this is not needed anymore.
    
    Signed-off-by: Simo Sorce <idra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/tevent/tevent.h          |    4 ++--
 lib/tevent/tevent_epoll.c    |   19 +++++++++++++++++--
 lib/tevent/tevent_standard.c |   17 +++++++++++++++++
 lib/tevent/tevent_util.c     |   17 +++++++++++++++++
 lib/tevent/tevent_util.h     |    1 +
 5 files changed, 54 insertions(+), 4 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h
index 6e3ed76..c38f7c3 100644
--- a/lib/tevent/tevent.h
+++ b/lib/tevent/tevent.h
@@ -111,7 +111,7 @@ typedef void (*tevent_signal_handler_t)(struct tevent_context *ev,
 struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx);
 
 /**
- * @brief Create a event_context structure and name it.
+ * @brief Create a event_context structure and select a specific backend.
  *
  * This must be the first events call, and all subsequent calls pass this
  * event_context as the first element. Event handlers also receive this as
@@ -119,7 +119,7 @@ struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx);
  *
  * @param[in]  mem_ctx  The memory context to use.
  *
- * @param[in]  name     The name for the tevent context.
+ * @param[in]  name     The name of the backend to use.
  *
  * @return              An allocated tevent context, NULL on error.
  */
diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c
index 3ab8283..33e1d3f 100644
--- a/lib/tevent/tevent_epoll.c
+++ b/lib/tevent/tevent_epoll.c
@@ -78,11 +78,20 @@ static int epoll_ctx_destructor(struct epoll_event_context *epoll_ev)
 static int epoll_init_ctx(struct epoll_event_context *epoll_ev)
 {
 	epoll_ev->epoll_fd = epoll_create(64);
-	epoll_ev->pid = getpid();
-	talloc_set_destructor(epoll_ev, epoll_ctx_destructor);
 	if (epoll_ev->epoll_fd == -1) {
+		tevent_debug(epoll_ev->ev, TEVENT_DEBUG_FATAL,
+			     "Failed to create epoll handle.\n");
 		return -1;
 	}
+
+	if (!ev_set_close_on_exec(epoll_ev->epoll_fd)) {
+		tevent_debug(epoll_ev->ev, TEVENT_DEBUG_WARNING,
+			     "Failed to set close-on-exec, file descriptor may be leaked to children.\n");
+	}
+
+	epoll_ev->pid = getpid();
+	talloc_set_destructor(epoll_ev, epoll_ctx_destructor);
+
 	return 0;
 }
 
@@ -108,6 +117,12 @@ static void epoll_check_reopen(struct epoll_event_context *epoll_ev)
 			     "Failed to recreate epoll handle after fork\n");
 		return;
 	}
+
+	if (!ev_set_close_on_exec(epoll_ev->epoll_fd)) {
+		tevent_debug(epoll_ev->ev, TEVENT_DEBUG_WARNING,
+			     "Failed to set close-on-exec, file descriptor may be leaked to children.\n");
+	}
+
 	epoll_ev->pid = getpid();
 	for (fde=epoll_ev->ev->fd_events;fde;fde=fde->next) {
 		epoll_add_event(epoll_ev, fde);
diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c
index 35f7ded..e2ca44f 100644
--- a/lib/tevent/tevent_standard.c
+++ b/lib/tevent/tevent_standard.c
@@ -100,6 +100,17 @@ static int epoll_ctx_destructor(struct std_event_context *std_ev)
 static void epoll_init_ctx(struct std_event_context *std_ev)
 {
 	std_ev->epoll_fd = epoll_create(64);
+	if (std_ev->epoll_fd == -1) {
+		tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL,
+			     "Failed to create epoll handle.\n");
+		return;
+	}
+
+	if (!ev_set_close_on_exec(std_ev->epoll_fd)) {
+		tevent_debug(std_ev->ev, TEVENT_DEBUG_WARNING,
+			     "Failed to set close-on-exec, file descriptor may be leaked to children.\n");
+	}
+
 	std_ev->pid = getpid();
 	talloc_set_destructor(std_ev, epoll_ctx_destructor);
 }
@@ -126,6 +137,12 @@ static void epoll_check_reopen(struct std_event_context *std_ev)
 			     "Failed to recreate epoll handle after fork\n");
 		return;
 	}
+
+	if (!ev_set_close_on_exec(std_ev->epoll_fd)) {
+		tevent_debug(std_ev->ev, TEVENT_DEBUG_WARNING,
+			     "Failed to set close-on-exec, file descriptor may be leaked to children.\n");
+	}
+
 	std_ev->pid = getpid();
 	for (fde=std_ev->ev->fd_events;fde;fde=fde->next) {
 		epoll_add_event(std_ev, fde);
diff --git a/lib/tevent/tevent_util.c b/lib/tevent/tevent_util.c
index f78cd8f..16af8f3 100644
--- a/lib/tevent/tevent_util.c
+++ b/lib/tevent/tevent_util.c
@@ -88,3 +88,20 @@ int ev_set_blocking(int fd, bool set)
 	return fcntl( fd, F_SETFL, val);
 #undef FLAG_TO_SET
 }
+
+bool ev_set_close_on_exec(int fd)
+{
+#ifdef FD_CLOEXEC
+	int val;
+
+	val = fcntl(fd, F_GETFD, 0);
+	if (val >= 0) {
+		val |= FD_CLOEXEC;
+		val = fcntl(fd, F_SETFD, val);
+		if (val != -1) {
+			return true;
+		}
+	}
+#endif
+	return false;
+}
diff --git a/lib/tevent/tevent_util.h b/lib/tevent/tevent_util.h
index 46a4506..311be60 100644
--- a/lib/tevent/tevent_util.h
+++ b/lib/tevent/tevent_util.h
@@ -183,6 +183,7 @@ do { \
 const char **ev_str_list_add(const char **list, const char *s);
 int ev_set_blocking(int fd, bool set);
 size_t ev_str_list_length(const char **list);
+bool ev_set_close_on_exec(int fd);
 
 /* Defined here so we can build against older talloc versions that don't
  * have this define yet. */


-- 
Samba Shared Repository


More information about the samba-cvs mailing list