[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-523-g93c2057

Stefan Metzmacher metze at samba.org
Wed Mar 18 06:34:19 GMT 2009


The branch, master has been updated
       via  93c2057c8b5a3976cda65a9d27dc4dbb9c5c550a (commit)
       via  3b8dd79f2bc775ed94130565ec2c4383a4864348 (commit)
       via  0685031ccfc09feb0ad070df1c1a1d0cef5874f2 (commit)
       via  450252d2a1981fb04eb62eb095c1b762a96f7727 (commit)
       via  b659daf81f31678f7447545d015bd9d1db8811b9 (commit)
       via  339ea0503d5ce3bf85cf61528956345c73c668c6 (commit)
       via  445b37f4f35ff4256c46dbacc2d3b3a1e47e62b2 (commit)
      from  cd7f62ab70337ccee7ba652e7d9ed8d299938bff (commit)

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


- Log -----------------------------------------------------------------
commit 93c2057c8b5a3976cda65a9d27dc4dbb9c5c550a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 17:27:30 2009 +0100

    s3:winbindd: accept new connections via fd events
    
    metze

commit 3b8dd79f2bc775ed94130565ec2c4383a4864348
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 16:14:20 2009 +0100

    s3:winbindd: move non event related code out of process_loop() in the the caller
    
    metze

commit 0685031ccfc09feb0ad070df1c1a1d0cef5874f2
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 16:06:12 2009 +0100

    s3:winbindd: remove unused close_winbindd_socket() function
    
    metze

commit 450252d2a1981fb04eb62eb095c1b762a96f7727
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 15:55:39 2009 +0100

    s3:smbd: use tevent_loop_once() in the parent event loop
    
    metze

commit b659daf81f31678f7447545d015bd9d1db8811b9
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 15:47:57 2009 +0100

    s3:printing: use tevent_loop_wait() instead of manual looping
    
    metze

commit 339ea0503d5ce3bf85cf61528956345c73c668c6
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 14:56:11 2009 +0100

    s3:printing: use a fd event to monitor the pipe to the parent
    
    metze

commit 445b37f4f35ff4256c46dbacc2d3b3a1e47e62b2
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Mar 16 14:48:40 2009 +0100

    s3:smbd: don't exit the parent when we have no connections
    
    This code path can't really happen anymore, because
    launchd support was removed with commit e5a951325a6cac8567af3a66de6d2df577508ae4.
    But it's confusing to have that code there...
    
    metze

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

Summary of changes:
 source3/printing/printing.c       |   82 ++++++----------
 source3/smbd/server.c             |   46 +--------
 source3/winbindd/winbindd.c       |  195 +++++++++++++++++++++++--------------
 source3/winbindd/winbindd_proto.h |    1 -
 source3/winbindd/winbindd_util.c  |   18 ----
 5 files changed, 155 insertions(+), 187 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index 71c6344..8524cfb 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -1387,6 +1387,18 @@ static void print_queue_receive(struct messaging_context *msg,
 	return;
 }
 
+static void printing_pause_fd_handler(struct tevent_context *ev,
+				      struct tevent_fd *fde,
+				      uint16_t flags,
+				      void *private_data)
+{
+	/*
+	 * If pause_pipe[1] is closed it means the parent smbd
+	 * and children exited or aborted.
+	 */
+	exit_server_cleanly(NULL);
+}
+
 static pid_t background_lpq_updater_pid = -1;
 
 /****************************************************************************
@@ -1415,6 +1427,9 @@ void start_background_queue(void)
 	}
 
 	if(background_lpq_updater_pid == 0) {
+		struct tevent_fd *fde;
+		int ret;
+
 		/* Child. */
 		DEBUG(5,("start_background_queue: background LPQ thread started\n"));
 
@@ -1440,60 +1455,21 @@ void start_background_queue(void)
 		messaging_register(smbd_messaging_context(), NULL,
 				   MSG_PRINTER_UPDATE, print_queue_receive);
 
-		DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
-		while (1) {
-			fd_set r_fds, w_fds;
-			int ret;
-			struct timeval to;
-			int maxfd = 0;
-
-			/* Process a signal and timed events now... */
-			if (run_events(smbd_event_context(), 0, NULL, NULL)) {
-				continue;
-			}
-
-			to.tv_sec = SMBD_SELECT_TIMEOUT;
-			to.tv_usec = 0;
-
-			/*
-			 * Setup the select fd sets.
-			 */
-
-			FD_ZERO(&r_fds);
-			FD_ZERO(&w_fds);
-
-			/*
-			 * Are there any timed events waiting ? If so, ensure we don't
-			 * select for longer than it would take to wait for them.
-			 */
-
-			{
-				struct timeval now;
-				GetTimeOfDay(&now);
-
-				event_add_to_select_args(smbd_event_context(), &now,
-							 &r_fds, &w_fds, &to, &maxfd);
-			}
-
-			FD_SET(pause_pipe[1], &r_fds);
-			maxfd = MAX(pause_pipe[1], maxfd);
-
-			ret = sys_select(maxfd, &r_fds, &w_fds, NULL, &to);
-
-			/*
-			 * If pause_pipe[1] is closed it means the parent smbd
-			 * and children exited or aborted. If sys_select()
-			 * failed, then something more sinister is wrong
-			 */
-			if ((ret < 0) ||
-			    (ret == 1 && FD_ISSET(pause_pipe[1], &r_fds))) {
-                                exit_server_cleanly(NULL);
-			}
-
-			if (run_events(smbd_event_context(), ret, &r_fds, &w_fds)) {
-				continue;
-			}
+		fde = tevent_add_fd(smbd_event_context(), smbd_event_context(),
+				    pause_pipe[1], TEVENT_FD_READ,
+				    printing_pause_fd_handler,
+				    NULL);
+		if (!fde) {
+			DEBUG(0,("tevent_add_fd() failed for pause_pipe\n"));
+			smb_panic("tevent_add_fd() failed for pause_pipe");
 		}
+
+		DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
+		ret = tevent_loop_wait(smbd_event_context());
+		/* should not be reached */
+		DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
+			 ret, (ret == 0) ? "out of events" : strerror(errno)));
+		exit(1);
 	}
 
 	close(pause_pipe[1]);
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 538e049..d27f982 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -654,52 +654,16 @@ static void smbd_parent_loop(struct smbd_parent_context *parent)
 {
 	/* now accept incoming connections - forking a new process
 	   for each incoming connection */
-	DEBUG(2,("waiting for a connection\n"));
+	DEBUG(2,("waiting for connections\n"));
 	while (1) {
-		struct timeval now, idle_timeout;
-		fd_set r_fds, w_fds;
-		int maxfd = 0;
-		int num;
+		int ret;
 		TALLOC_CTX *frame = talloc_stackframe();
 
-		if (run_events(smbd_event_context(), 0, NULL, NULL)) {
-			TALLOC_FREE(frame);
-			continue;
-		}
-
-		idle_timeout = timeval_zero();
-
-		FD_ZERO(&w_fds);
-		FD_ZERO(&r_fds);
-		GetTimeOfDay(&now);
-
-		event_add_to_select_args(smbd_event_context(), &now,
-					 &r_fds, &w_fds, &idle_timeout,
-					 &maxfd);
-
-		num = sys_select(maxfd+1,&r_fds,&w_fds,NULL,
-				 timeval_is_zero(&idle_timeout) ?
-				 NULL : &idle_timeout);
-
-		/* check if we need to reload services */
-		check_reload(time(NULL));
-
-		if (run_events(smbd_event_context(), num, &r_fds, &w_fds)) {
-			TALLOC_FREE(frame);
-			continue;
+		ret = tevent_loop_once(smbd_event_context());
+		if (ret != 0) {
+			exit_server_cleanly("tevent_loop_once() error");
 		}
 
-		/* socket error */
-		if (num < 0)
-			exit_server_cleanly("socket error");
-
-		/* If the idle timeout fired and we don't have any connected
-		 * users, exit gracefully. We should be running under a process
-		 * controller that will restart us if necessry.
-		 */
-		if (num == 0 && count_all_current_connections() == 0) {
-			exit_server_cleanly("idle timeout");
-		}
 		TALLOC_FREE(frame);
 	} /* end while 1 */
 
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index f5812f9..6627106 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -927,6 +927,97 @@ static bool remove_idle_client(void)
 	return False;
 }
 
+struct winbindd_listen_state {
+	bool privileged;
+	int fd;
+	struct tevent_fd *fde;
+};
+
+static void winbindd_listen_fde_handler(struct tevent_context *ev,
+					struct tevent_fd *fde,
+					uint16_t flags,
+					void *private_data)
+{
+	struct winbindd_listen_state *s = talloc_get_type_abort(private_data,
+					  struct winbindd_listen_state);
+
+	while (winbindd_num_clients() >
+	       WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
+		DEBUG(5,("winbindd: Exceeding %d client "
+			 "connections, removing idle "
+			 "connection.\n",
+			 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
+		if (!remove_idle_client()) {
+			DEBUG(0,("winbindd: Exceeding %d "
+				 "client connections, no idle "
+				 "connection found\n",
+				 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
+			break;
+		}
+	}
+
+	/* new, non-privileged connection */
+	new_connection(s->fd, s->privileged);
+}
+
+static bool winbindd_setup_listeners(void)
+{
+	struct winbindd_listen_state *pub_state = NULL;
+	struct winbindd_listen_state *priv_state = NULL;
+
+	pub_state = talloc(winbind_event_context(),
+			   struct winbindd_listen_state);
+	if (!pub_state) {
+		goto failed;
+	}
+
+	pub_state->privileged = false;
+	pub_state->fd = open_winbindd_socket();
+	if (pub_state->fd == -1) {
+		goto failed;
+	}
+
+	pub_state->fde = tevent_add_fd(winbind_event_context(),
+				       pub_state, pub_state->fd,
+				       TEVENT_FD_READ,
+				       winbindd_listen_fde_handler,
+				       pub_state);
+	if (!pub_state->fde) {
+		close(pub_state->fd);
+		goto failed;
+	}
+	tevent_fd_set_auto_close(pub_state->fde);
+
+	priv_state = talloc(winbind_event_context(),
+			    struct winbindd_listen_state);
+	if (!priv_state) {
+		goto failed;
+	}
+
+	priv_state->privileged = true;
+	priv_state->fd = open_winbindd_priv_socket();
+	if (priv_state->fd == -1) {
+		goto failed;
+	}
+
+	priv_state->fde = tevent_add_fd(winbind_event_context(),
+					priv_state, priv_state->fd,
+					TEVENT_FD_READ,
+					winbindd_listen_fde_handler,
+					priv_state);
+	if (!priv_state->fde) {
+		close(priv_state->fd);
+		goto failed;
+	}
+	tevent_fd_set_auto_close(priv_state->fde);
+
+	return true;
+failed:
+	TALLOC_FREE(pub_state);
+	TALLOC_FREE(priv_state);
+	return false;
+}
+
 /* Process incoming clients on listen_sock.  We use a tricky non-blocking,
    non-forking, non-threaded model which allows us to handle many
    simultaneous connections while remaining impervious to many denial of
@@ -934,35 +1025,17 @@ static bool remove_idle_client(void)
 
 static void process_loop(void)
 {
-	struct winbindd_cli_state *state;
 	struct winbindd_fd_event *ev;
 	fd_set r_fds, w_fds;
-	int maxfd, listen_sock, listen_priv_sock, selret;
+	int maxfd = 0, selret;
 	struct timeval timeout, ev_timeout;
 
-	/* Open Sockets here to get stuff going ASAP */
-	listen_sock = open_winbindd_socket();
-	listen_priv_sock = open_winbindd_priv_socket();
-
-	if (listen_sock == -1 || listen_priv_sock == -1) {
-		perror("open_winbind_socket");
-		exit(1);
-	}
-
 	run_events(winbind_event_context(), 0, NULL, NULL);
 
-	/* refresh the trusted domain cache */
-
-	rescan_trusted_domains();
-
 	/* Initialise fd lists for select() */
 
-	maxfd = MAX(listen_sock, listen_priv_sock);
-
 	FD_ZERO(&r_fds);
 	FD_ZERO(&w_fds);
-	FD_SET(listen_sock, &r_fds);
-	FD_SET(listen_priv_sock, &r_fds);
 
 	timeout.tv_sec = WINBINDD_ESTABLISH_LOOP;
 	timeout.tv_usec = 0;
@@ -979,23 +1052,6 @@ static void process_loop(void)
 		timeout = timeval_min(&timeout, &ev_timeout);
 	}
 
-	/* Set up client readers and writers */
-
-	state = winbindd_client_list();
-
-	while (state) {
-
-		struct winbindd_cli_state *next = state->next;
-
-		/* Dispose of client connection if it is marked as 
-		   finished */ 
-
-		if (state->finished)
-			remove_client(state);
-
-		state = next;
-	}
-
 	for (ev = fd_events; ev; ev = ev->next) {
 		if (ev->flags & EVENT_FD_READ) {
 			FD_SET(ev->fd, &r_fds);
@@ -1043,43 +1099,7 @@ static void process_loop(void)
 		ev = next;
 	}
 
-	if (FD_ISSET(listen_sock, &r_fds)) {
-		while (winbindd_num_clients() >
-		       WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
-			DEBUG(5,("winbindd: Exceeding %d client "
-				 "connections, removing idle "
-				 "connection.\n",
-				 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
-			if (!remove_idle_client()) {
-				DEBUG(0,("winbindd: Exceeding %d "
-					 "client connections, no idle "
-					 "connection found\n",
-					 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
-				break;
-			}
-		}
-		/* new, non-privileged connection */
-		new_connection(listen_sock, False);
-	}
-
-	if (FD_ISSET(listen_priv_sock, &r_fds)) {
-		while (winbindd_num_clients() >
-		       WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
-			DEBUG(5,("winbindd: Exceeding %d client "
-				 "connections, removing idle "
-				 "connection.\n",
-				 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
-			if (!remove_idle_client()) {
-				DEBUG(0,("winbindd: Exceeding %d "
-					 "client connections, no idle "
-					 "connection found\n",
-					 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
-				break;
-			}
-		}
-		/* new, privileged connection */
-		new_connection(listen_priv_sock, True);
-	}
+	return;
 
  no_fds_ready:
 
@@ -1366,12 +1386,39 @@ int main(int argc, char **argv, char **envp)
 	smb_nscd_flush_user_cache();
 	smb_nscd_flush_group_cache();
 
-	/* Loop waiting for requests */
+	/* setup listen sockets */
+
+	if (!winbindd_setup_listeners()) {
+		DEBUG(0,("winbindd_setup_listeners() failed\n"));
+		exit(1);
+	}
 
 	TALLOC_FREE(frame);
+	/* Loop waiting for requests */
 	while (1) {
+		struct winbindd_cli_state *state;
+
 		frame = talloc_stackframe();
+
+		/* refresh the trusted domain cache */
+
+		rescan_trusted_domains();
+
+		/* Dispose of client connection if it is marked as
+		   finished */
+		state = winbindd_client_list();
+		while (state) {
+			struct winbindd_cli_state *next = state->next;
+
+			if (state->finished) {
+				remove_client(state);
+			}
+
+			state = next;
+		}
+
 		process_loop();
+
 		TALLOC_FREE(frame);
 	}
 
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 4fc96e8..9a36512 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -549,7 +549,6 @@ const char *get_winbind_pipe_dir(void) ;
 char *get_winbind_priv_pipe_dir(void) ;
 int open_winbindd_socket(void);
 int open_winbindd_priv_socket(void);
-void close_winbindd_socket(void);
 struct winbindd_cli_state *winbindd_client_list(void);
 void winbindd_add_client(struct winbindd_cli_state *cli);
 void winbindd_remove_client(struct winbindd_cli_state *cli);
diff --git a/source3/winbindd/winbindd_util.c b/source3/winbindd/winbindd_util.c
index 2d87015..a2c1c85 100644
--- a/source3/winbindd/winbindd_util.c
+++ b/source3/winbindd/winbindd_util.c
@@ -1316,24 +1316,6 @@ int open_winbindd_priv_socket(void)
 	return _winbindd_priv_socket;
 }
 
-/* Close the winbindd socket */
-
-void close_winbindd_socket(void)
-{
-	if (_winbindd_socket != -1) {
-		DEBUG(10, ("close_winbindd_socket: closing socket fd %d\n",
-			   _winbindd_socket));
-		close(_winbindd_socket);
-		_winbindd_socket = -1;
-	}
-	if (_winbindd_priv_socket != -1) {
-		DEBUG(10, ("close_winbindd_socket: closing socket fd %d\n",
-			   _winbindd_priv_socket));
-		close(_winbindd_priv_socket);
-		_winbindd_priv_socket = -1;
-	}
-}
-
 /*
  * Client list accessor functions
  */


-- 
Samba Shared Repository


More information about the samba-cvs mailing list