[Date Prev][Date Next] [Chronological] [Thread] [Top]

slapd connection variables are not reset properly



The run-from-inetd case in slapd main() does not perform
   pthread_cond_init( &c.c_wcv, pthread_condattr_default )
like daemon.c does.  I don't know if that is a daemon-specific mutex;
it's used in result.c.


Slapd needs the following patch, if it is correct.  Please check.
Connection.c_sb.sb_sd should apparently be -1 for unused file
descriptors.  And Connection.c_version should be reset to 0 when a
connection closes (it is not reset when a connection is opened).  Also,
the run-from-inetd case did not initialize as many fields in Connection
as daemon case, maybe it was written before the new fields were added.
I took the easy way out and initialize them from a null-filled nullconn
variable, then the code won't have to worry about which fields to zero
out.

Index: proto-slap.h
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/proto-slap.h,v
retrieving revision 1.7
diff -u -2 -r1.7 proto-slap.h
--- proto-slap.h	1998/11/15 21:40:21	1.7
+++ proto-slap.h	1998/11/20 13:12:23
@@ -222,4 +222,5 @@
  */
 
+extern const Connection	nullconn;
 extern char		**g_argv;
 extern char		*default_referral;
Index: daemon.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/daemon.c,v
retrieving revision 1.16
diff -u -2 -r1.16 daemon.c
--- daemon.c	1998/11/18 16:45:32	1.16
+++ daemon.c	1998/11/20 13:12:08
@@ -34,4 +34,6 @@
 #endif /* TCP Wrappers */
 
+const Connection nullconn;	/* With null fields only, for initialization */
+
 int		dtblsize;
 Connection	*c;
@@ -70,19 +72,10 @@
 #endif	/* !FD_SETSIZE */
 
-	c = (Connection *) ch_calloc( 1, dtblsize * sizeof(Connection) );
+	c = (Connection *) malloc( dtblsize * sizeof(Connection) );
 
 	for ( i = 0; i < dtblsize; i++ ) {
-		c[i].c_dn = NULL;
-		c[i].c_addr = NULL;
-		c[i].c_domain = NULL;
-		c[i].c_ops = NULL;
+		c[i] = nullconn;
 		c[i].c_sb.sb_sd = -1;
 		c[i].c_sb.sb_options = LBER_NO_READ_AHEAD;
-		c[i].c_sb.sb_naddr = 0;
-		c[i].c_sb.sb_ber.ber_buf = NULL;
-		c[i].c_sb.sb_ber.ber_ptr = NULL;
-		c[i].c_sb.sb_ber.ber_end = NULL;
-		c[i].c_writewaiter = 0;
-		c[i].c_connid = 0;
 		pthread_mutex_init( &c[i].c_dnmutex,
 		    pthread_mutexattr_default );
@@ -290,4 +283,6 @@
 
 				close(ns);
+			    	c[ns].c_sb.sb_sd = -1;
+			    	c[ns].c_version = 0;
 				pthread_mutex_unlock( &new_conn_mutex );
 				continue;
Index: main.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/main.c,v
retrieving revision 1.13
diff -u -2 -r1.13 main.c
--- main.c	1998/11/16 04:07:34	1.13
+++ main.c	1998/11/20 13:12:22
@@ -214,12 +214,7 @@
 		struct hostent		*hp;
 
-		c.c_dn = NULL;
-		c.c_ops = NULL;
-		c.c_sb.sb_sd = 0;
-		c.c_sb.sb_options = 0;
+		c = nullconn;
+		c.c_sb.sb_sd = -1;
 		c.c_sb.sb_naddr = udp ? 1 : 0;
-		c.c_sb.sb_ber.ber_buf = NULL;
-		c.c_sb.sb_ber.ber_ptr = NULL;
-		c.c_sb.sb_ber.ber_end = NULL;
 		pthread_mutex_init( &c.c_dnmutex, pthread_mutexattr_default );
 		pthread_mutex_init( &c.c_opsmutex, pthread_mutexattr_default );
@@ -274,4 +269,5 @@
 				close( c.c_sb.sb_sd );
 				c.c_sb.sb_sd = -1;
+				c.c_version = 0;
 				return 1;
 			}