[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Thu Feb 16 18:50:02 MST 2012


The branch, master has been updated
       via  ed85e9f Replace smbd_server_connection_loop_once() with tevent_loop_once() directly.
       via  367c567 lib/util: Remove sys_poll as it is no longer needed
       via  ab80995 lib/util: Remove unused sys_select_signal()
      from  91c325b s3-librpc: Remove gse_verify_server_auth_flags

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


- Log -----------------------------------------------------------------
commit ed85e9fe6a10d3c34b74788e6f862ea23dce4f2b
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Feb 16 16:14:14 2012 -0800

    Replace smbd_server_connection_loop_once() with tevent_loop_once() directly.
    
    We no longer need to call poll() directly inside smbd !
    
    Autobuild-User: Jeremy Allison <jra at samba.org>
    Autobuild-Date: Fri Feb 17 02:49:13 CET 2012 on sn-devel-104

commit 367c567c5f35db202474c8d3f730484538e1fb97
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Feb 9 13:16:55 2012 +1100

    lib/util: Remove sys_poll as it is no longer needed
    
    sys_poll() is only needed if the signal pipe is set up and used, but as
    no signal handler ever writes to the pipe, this can all be removed.
    
    signal based events are now handled via tevent.
    
    Andrew Bartlett
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit ab80995580f092811d6380caa9e71e4c5fda06f4
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu Feb 9 13:02:14 2012 +1100

    lib/util: Remove unused sys_select_signal()
    
    Now sys_poll needs to be cleaned up not to refer to the pipe that is now not used.
    
    Andrew Bartlett
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 lib/util/select.c                |  108 --------------------------------------
 lib/util/select.h                |    2 -
 source3/lib/events.c             |   11 +---
 source3/lib/g_lock.c             |   12 ++--
 source3/lib/util_sock.c          |    4 +-
 source3/nmbd/nmbd_packets.c      |    2 +-
 source3/smbd/process.c           |   69 ++----------------------
 source3/winbindd/winbindd_dual.c |    2 +-
 8 files changed, 19 insertions(+), 191 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/select.c b/lib/util/select.c
index b9326ef..5e66344 100644
--- a/lib/util/select.c
+++ b/lib/util/select.c
@@ -23,114 +23,6 @@
 #include "system/select.h"
 #include "lib/util/select.h"
 
-/* This is here because it allows us to avoid a nasty race in signal handling.
-   We need to guarantee that when we get a signal we get out of a select immediately
-   but doing that involves a race condition. We can avoid the race by getting the
-   signal handler to write to a pipe that is in the select/poll list
-
-   This means all Samba signal handlers should call sys_select_signal().
-*/
-
-static pid_t initialised;
-static int select_pipe[2];
-static volatile unsigned pipe_written, pipe_read;
-
-/*******************************************************************
- Call this from all Samba signal handlers if you want to avoid a
- nasty signal race condition.
-********************************************************************/
-
-void sys_select_signal(char c)
-{
-	int saved_errno = errno;
-
-	if (!initialised) return;
-
-	if (pipe_written > pipe_read+256) return;
-
-	if (write(select_pipe[1], &c, 1) == 1) pipe_written++;
-
-	errno = saved_errno;
-}
-
-/*
- * sys_poll expects pollfd's to be a talloc'ed array.
- *
- * It expects the talloc_array_length(fds) >= num_fds+1 to give space
- * to the signal pipe.
- */
-
-int sys_poll(struct pollfd *fds, int num_fds, int timeout)
-{
-	int ret;
-
-	if (talloc_array_length(fds) < num_fds+1) {
-		errno = ENOSPC;
-		return -1;
-	}
-
-	if (initialised != sys_getpid()) {
-		if (pipe(select_pipe) == -1)
-		{
-			int saved_errno = errno;
-			DEBUG(0, ("sys_poll: pipe failed (%s)\n",
-				strerror(errno)));
-			errno = saved_errno;
-			return -1;
-		}
-
-		/*
-		 * These next two lines seem to fix a bug with the Linux
-		 * 2.0.x kernel (and probably other UNIXes as well) where
-		 * the one byte read below can block even though the
-		 * select returned that there is data in the pipe and
-		 * the pipe_written variable was incremented. Thanks to
-		 * HP for finding this one. JRA.
-		 */
-
-		if(set_blocking(select_pipe[0],0)==-1)
-			smb_panic("select_pipe[0]: O_NONBLOCK failed");
-		if(set_blocking(select_pipe[1],0)==-1)
-			smb_panic("select_pipe[1]: O_NONBLOCK failed");
-
-		initialised = sys_getpid();
-	}
-
-	ZERO_STRUCT(fds[num_fds]);
-	fds[num_fds].fd = select_pipe[0];
-	fds[num_fds].events = POLLIN|POLLHUP;
-
-	errno = 0;
-	ret = poll(fds, num_fds+1, timeout);
-
-	if ((ret >= 0) && (fds[num_fds].revents & (POLLIN|POLLHUP|POLLERR))) {
-		char c;
-		int saved_errno = errno;
-
-		if (read(select_pipe[0], &c, 1) == 1) {
-			pipe_read += 1;
-
-			/* Mark Weaver <mark-clist at npsl.co.uk> pointed out a critical
-			   fix to ensure we don't lose signals. We must always
-			   return -1 when the select pipe is set, otherwise if another
-			   fd is also ready (so ret == 2) then we used to eat the
-			   byte in the pipe and lose the signal. JRA.
-			*/
-			ret = -1;
-#if 0
-			/* JRA - we can use this to debug the signal messaging... */
-			DEBUG(0,("select got %u signal\n", (unsigned int)c));
-#endif
-			errno = EINTR;
-		} else {
-			ret -= 1;
-			errno = saved_errno;
-		}
-	}
-
-	return ret;
-}
-
 int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout)
 {
 	int orig_timeout = timeout;
diff --git a/lib/util/select.h b/lib/util/select.h
index 36efa6e..fa1970e 100644
--- a/lib/util/select.h
+++ b/lib/util/select.h
@@ -24,8 +24,6 @@
 
 /* The following definitions come from lib/util/select.c  */
 
-void sys_select_signal(char c);
-int sys_poll(struct pollfd *fds, int num_fds, int timeout);
 int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout);
 
 #endif
diff --git a/source3/lib/events.c b/source3/lib/events.c
index 77589f8..c71876c 100644
--- a/source3/lib/events.c
+++ b/source3/lib/events.c
@@ -101,14 +101,9 @@ bool event_add_to_poll_args(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
 	fds = *pfds;
 	num_pollfds = *pnum_pfds;
 
-	/*
-	 * The +1 is for the sys_poll calling convention. It expects
-	 * an array 1 longer for the signal pipe
-	 */
-
-	if (talloc_array_length(fds) < num_pollfds + num_fds + 1) {
+	if (talloc_array_length(fds) < num_pollfds + num_fds) {
 		fds = talloc_realloc(mem_ctx, fds, struct pollfd,
-					   num_pollfds + num_fds + 1);
+					   num_pollfds + num_fds);
 		if (fds == NULL) {
 			DEBUG(10, ("talloc_realloc failed\n"));
 			return false;
@@ -338,7 +333,7 @@ static int s3_event_loop_once(struct tevent_context *ev, const char *location)
 		return -1;
 	}
 
-	ret = sys_poll(state->pfds, num_pfds, timeout);
+	ret = poll(state->pfds, num_pfds, timeout);
 	if (ret == -1 && errno != EINTR) {
 		tevent_debug(ev, TEVENT_DEBUG_FATAL,
 			     "poll() failed: %d:%s\n",
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 1fd8ae9..1011584 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -395,11 +395,11 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
 		 */
 
 		/*
-		 * We allocate 2 entries here. One is needed anyway for
-		 * sys_poll and in the clustering case we might have to add
-		 * the ctdb fd. This avoids the realloc then.
+		 * We allocate 1 entries here. In the clustering case
+		 * we might have to add the ctdb fd. This avoids the
+		 * realloc then.
 		 */
-		pollfds = talloc_array(talloc_tos(), struct pollfd, 2);
+		pollfds = talloc_array(talloc_tos(), struct pollfd, 1);
 		if (pollfds == NULL) {
 			status = NT_STATUS_NO_MEMORY;
 			break;
@@ -425,8 +425,8 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
 		select_timeout = timeval_min(&select_timeout,
 					     &timeout_remaining);
 
-		ret = sys_poll(pollfds, num_pollfds,
-			       timeval_to_msec(select_timeout));
+		ret = poll(pollfds, num_pollfds,
+			   timeval_to_msec(select_timeout));
 
 		/*
 		 * We're not *really interested in the actual flags. We just
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index dcc41bb..69e33f7 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -1604,7 +1604,7 @@ int poll_one_fd(int fd, int events, int timeout, int *revents)
 	int ret;
 	int saved_errno;
 
-	fds = talloc_zero_array(talloc_tos(), struct pollfd, 2);
+	fds = talloc_zero_array(talloc_tos(), struct pollfd, 1);
 	if (fds == NULL) {
 		errno = ENOMEM;
 		return -1;
@@ -1612,7 +1612,7 @@ int poll_one_fd(int fd, int events, int timeout, int *revents)
 	fds[0].fd = fd;
 	fds[0].events = events;
 
-	ret = sys_poll(fds, 1, timeout);
+	ret = poll(fds, 1, timeout);
 
 	/*
 	 * Assign whatever poll did, even in the ret<=0 case.
diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c
index edac6f6..81e2f7f 100644
--- a/source3/nmbd/nmbd_packets.c
+++ b/source3/nmbd/nmbd_packets.c
@@ -1935,7 +1935,7 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election)
 	event_add_to_poll_args(nmbd_event_context(), NULL,
 			       &fds, &num_sockets, &timeout);
 
-	pollrtn = sys_poll(fds, num_sockets, timeout);
+	pollrtn = poll(fds, num_sockets, timeout);
 
 	if (run_events_poll(nmbd_event_context(), pollrtn, fds, num_sockets)) {
 		return False;
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 2f8f88f..1d74355 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -941,60 +941,6 @@ static void smbd_conf_updated(struct messaging_context *msg,
 	reload_services(sconn, conn_snum_used, false);
 }
 
-static NTSTATUS smbd_server_connection_loop_once(struct tevent_context *ev_ctx,
-						 struct smbd_server_connection *conn)
-{
-	int timeout;
-	int num_pfds = 0;
-	int ret;
-	bool retry;
-
-	timeout = SMBD_SELECT_TIMEOUT * 1000;
-
-	/*
-	 * Are there any timed events waiting ? If so, ensure we don't
-	 * select for longer than it would take to wait for them.
-	 */
-
-	event_add_to_poll_args(ev_ctx, conn, &conn->pfds, &num_pfds, &timeout);
-
-	/* Process a signal and timed events now... */
-	if (run_events_poll(ev_ctx, 0, NULL, 0)) {
-		return NT_STATUS_RETRY;
-	}
-
-	{
-		int sav;
-		START_PROFILE(smbd_idle);
-
-		ret = sys_poll(conn->pfds, num_pfds, timeout);
-		sav = errno;
-
-		END_PROFILE(smbd_idle);
-		errno = sav;
-	}
-
-	if (ret == -1) {
-		if (errno == EINTR) {
-			return NT_STATUS_RETRY;
-		}
-		return map_nt_error_from_unix(errno);
-	}
-
-	retry = run_events_poll(ev_ctx, ret, conn->pfds, num_pfds);
-	if (retry) {
-		return NT_STATUS_RETRY;
-	}
-
-	/* Did we timeout ? */
-	if (ret == 0) {
-		return NT_STATUS_RETRY;
-	}
-
-	/* should not be reached */
-	return NT_STATUS_INTERNAL_ERROR;
-}
-
 /*
  * Only allow 5 outstanding trans requests. We're allocating memory, so
  * prevent a DoS.
@@ -3380,18 +3326,15 @@ void smbd_process(struct tevent_context *ev_ctx,
 	TALLOC_FREE(frame);
 
 	while (True) {
-		NTSTATUS status;
-
 		frame = talloc_stackframe_pool(8192);
 
 		errno = 0;
-
-		status = smbd_server_connection_loop_once(ev_ctx, sconn);
-		if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY) &&
-		    !NT_STATUS_IS_OK(status)) {
-			DEBUG(3, ("smbd_server_connection_loop_once failed: %s,"
-				  " exiting\n", nt_errstr(status)));
-			break;
+		if (tevent_loop_once(ev_ctx) == -1) {
+			if (errno != EINTR) {
+				DEBUG(3, ("tevent_loop_once failed: %s,"
+					  " exiting\n", strerror(errno) ));
+				break;
+			}
 		}
 
 		TALLOC_FREE(frame);
diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c
index d0bcd3b..f11dae7 100644
--- a/source3/winbindd/winbindd_dual.c
+++ b/source3/winbindd/winbindd_dual.c
@@ -1507,7 +1507,7 @@ static bool fork_domain_child(struct winbindd_child *child)
 				(unsigned int)tp->tv_sec, (unsigned int)tp->tv_usec ));
 		}
 
-		ret = sys_poll(pfds, num_pfds, timeout);
+		ret = poll(pfds, num_pfds, timeout);
 
 		if (run_events_poll(winbind_event_context(), ret,
 				    pfds, num_pfds)) {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list