svn commit: samba r21871 - in branches/SAMBA_3_0/source/smbd: .

vlendec at samba.org vlendec at samba.org
Sun Mar 18 13:19:41 GMT 2007


Author: vlendec
Date: 2007-03-18 13:19:40 +0000 (Sun, 18 Mar 2007)
New Revision: 21871

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

Log:
Move deadtime processing into an idle event. While there, simplify
conn_idle_all() a bit.

Volker


Modified:
   branches/SAMBA_3_0/source/smbd/conn.c
   branches/SAMBA_3_0/source/smbd/process.c
   branches/SAMBA_3_0/source/smbd/server.c


Changeset:
Modified: branches/SAMBA_3_0/source/smbd/conn.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/conn.c	2007-03-18 11:24:10 UTC (rev 21870)
+++ branches/SAMBA_3_0/source/smbd/conn.c	2007-03-18 13:19:40 UTC (rev 21871)
@@ -191,15 +191,15 @@
 {
 	int deadtime = lp_deadtime()*60;
 	pipes_struct *plist = NULL;
-	BOOL allidle = True;
-	connection_struct *conn, *next;
+	connection_struct *conn;
 
 	if (deadtime <= 0)
 		deadtime = DEFAULT_SMBD_TIMEOUT;
 
-	for (conn=Connections;conn;conn=next) {
-		next=conn->next;
+	for (conn=Connections;conn;conn=conn->next) {
 
+		time_t age = t - conn->lastused;
+
 		/* Update if connection wasn't idle. */
 		if (conn->lastused != conn->lastused_count) {
 			conn->lastused = t;
@@ -207,12 +207,12 @@
 		}
 
 		/* close dirptrs on connections that are idle */
-		if ((t-conn->lastused) > DPTR_IDLE_TIMEOUT) {
+		if (age > DPTR_IDLE_TIMEOUT) {
 			dptr_idlecnum(conn);
 		}
 
-		if (conn->num_files_open > 0 || (t-conn->lastused)<deadtime) {
-			allidle = False;
+		if (conn->num_files_open > 0 || age < deadtime) {
+			return False;
 		}
 	}
 
@@ -221,11 +221,14 @@
 	 * idle with a handle open.
 	 */
 
-	for (plist = get_first_internal_pipe(); plist; plist = get_next_internal_pipe(plist))
-		if (plist->pipe_handles && plist->pipe_handles->count)
-			allidle = False;
+	for (plist = get_first_internal_pipe(); plist;
+	     plist = get_next_internal_pipe(plist)) {
+		if (plist->pipe_handles && plist->pipe_handles->count) {
+			return False;
+		}
+	}
 	
-	return allidle;
+	return True;
 }
 
 /****************************************************************************
@@ -303,6 +306,8 @@
 	DLIST_REMOVE(Connections, conn);
 
 	bitmap_clear(bmap, conn->cnum);
+
+	SMB_ASSERT(num_open > 0);
 	num_open--;
 
 	conn_free_internal(conn);

Modified: branches/SAMBA_3_0/source/smbd/process.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/process.c	2007-03-18 11:24:10 UTC (rev 21870)
+++ branches/SAMBA_3_0/source/smbd/process.c	2007-03-18 13:19:40 UTC (rev 21871)
@@ -1328,9 +1328,7 @@
 static BOOL timeout_processing(int *select_timeout,
 			       time_t *last_timeout_processing_time)
 {
-	static time_t last_idle_closed_check = 0;
 	time_t t;
-	BOOL allidle = True;
 
 	if (smb_read_error == READ_EOF) {
 		DEBUG(3,("timeout_processing: End of file from client (client has disconnected).\n"));
@@ -1350,31 +1348,12 @@
 
 	*last_timeout_processing_time = t = time(NULL);
 
-	if(last_idle_closed_check == 0)
-		last_idle_closed_check = t;
-
 	/* become root again if waiting */
 	change_to_root_user();
 
 	/* check if we need to reload services */
 	check_reload(t);
 
-	/* automatic timeout if all connections are closed */      
-	if (conn_num_open()==0 && (t - last_idle_closed_check) >= IDLE_CLOSED_TIMEOUT) {
-		DEBUG( 2, ( "Closing idle connection\n" ) );
-		return False;
-	} else {
-		last_idle_closed_check = t;
-	}
-
-	/* check for connection timeouts */
-	allidle = conn_idle_all(t);
-
-	if (allidle && conn_num_open()>0) {
-		DEBUG(2,("Closing idle connection 2.\n"));
-		return False;
-	}
-
 	if(global_machine_password_needs_changing && 
 			/* for ADS we need to do a regular ADS password change, not a domain
 					password change */

Modified: branches/SAMBA_3_0/source/smbd/server.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/server.c	2007-03-18 11:24:10 UTC (rev 21870)
+++ branches/SAMBA_3_0/source/smbd/server.c	2007-03-18 13:19:40 UTC (rev 21871)
@@ -826,6 +826,22 @@
 	return True;
 }
 
+/*
+ * Do the recurring check if we're idle
+ */
+static BOOL deadtime_fn(const struct timeval *now, void *private_data)
+{
+	if ((conn_num_open() == 0)
+	    || (conn_idle_all(now->tv_sec))) {
+		DEBUG( 2, ( "Closing idle connection\n" ) );
+		message_send_pid(procid_self(), MSG_SHUTDOWN, NULL, 0, False);
+		return False;
+	}
+
+	return True;
+}
+
+
 /****************************************************************************
  main program.
 ****************************************************************************/
@@ -1119,18 +1135,20 @@
 	/* register our message handlers */
 	message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis, NULL);
 
-	if (lp_keepalive() != 0) {
-		struct timeval interval;
+	if ((lp_keepalive() != 0)
+	    && !(event_add_idle(smbd_event_context(), NULL,
+				timeval_set(lp_keepalive(), 0),
+				"keepalive", keepalive_fn,
+				NULL))) {
+		DEBUG(0, ("Could not add keepalive event\n"));
+		exit(1);
+	}
 
-		interval.tv_sec = lp_keepalive();
-		interval.tv_usec = 0;
-
-		if (!(event_add_idle(smbd_event_context(), NULL,
-				     interval, "keepalive", keepalive_fn,
-				     NULL))) {
-			DEBUG(0, ("Could not add keepalive event\n"));
-			exit(1);
-		}
+	if (!(event_add_idle(smbd_event_context(), NULL,
+			     timeval_set(IDLE_CLOSED_TIMEOUT, 0),
+			     "deadtime", deadtime_fn, NULL))) {
+		DEBUG(0, ("Could not add deadtime event\n"));
+		exit(1);
 	}
 
 	smbd_process();



More information about the samba-cvs mailing list