commit: r273 - trunk/daemon

[email protected]
Newsgroups gmane.network.spread.cvs
Message-ID <[email protected]>
Author: jonathan
Date: 2005-08-30 09:19:47 -0400 (Tue, 30 Aug 2005)
New Revision: 273

Modified:
   trunk/daemon/configuration.c
   trunk/daemon/network.c
Log:
Fix for dynamic conf bug that caused crash with corrupted Cn struct. 
Reported by Jacob Green. 


Modified: trunk/daemon/configuration.c
===================================================================
--- trunk/daemon/configuration.c	2005-08-30 01:51:05 UTC (rev 272)
+++ trunk/daemon/configuration.c	2005-08-30 13:19:47 UTC (rev 273)
@@ -110,6 +110,7 @@
 static  char    *Conf_MyName;
 
 static  int	Conf_prev_proc_by_id( int32u id, proc *p );
+static  void    Conf_config_copy( configuration *src_conf, configuration *dst_conf, proc *src_procs, proc *dst_procs);
 
 /* Hash function for string to 32 bit int */
 static LOC_INLINE int32u conf_hash_string(const void * key, int32u key_len)
@@ -188,15 +189,17 @@
         Config_Previous = Config;
         Config_Previous_Procs = Config_procs;
 
-        Config = Mem_alloc( sizeof( configuration ) );
-        if (Config == NULL) {
-                Alarmp( SPLOG_FATAL, CONF, "Conf_reload_initiate: Failed to allocate memory for configuration structure\n");
+        Config_Previous = Mem_alloc( sizeof( configuration ) );
+        if (Config_Previous == NULL) {
+                Alarmp( SPLOG_FATAL, CONF, "Conf_reload_initiate: Failed to allocate memory for old configuration structure\n");
         }
-        Config_procs = Mem_alloc( MAX_PROCS_RING * sizeof( proc ) );
-        if (Config_procs == NULL) {
-                Alarmp( SPLOG_FATAL, CONF, "Conf_reload_initiate: Failed to allocate memory for configuration procs array\n");
+        Config_Previous_Procs = Mem_alloc( MAX_PROCS_RING * sizeof( proc ) );
+        if (Config_Previous_Procs == NULL) {
+                Alarmp( SPLOG_FATAL, CONF, "Conf_reload_initiate: Failed to allocate memory for old configuration procs array\n");
         }
 
+        Conf_config_copy( Config, Config_Previous, Config_procs, Config_Previous_Procs );
+
         Conf_load_conf_file( Conf_FileName, Conf_MyName );
 
         /* Exit if:
@@ -515,6 +518,56 @@
 	}
 	return( -1 );
 }
+static  int     Conf_config_lookup_id( configuration *conf, proc *procs, int32u id)
+{
+	int	i,j;
+
+	for ( i=0; i < conf->num_total_procs; i++ )
+	{
+                for ( j=0; j < procs[i].num_if; j++)
+                {
+                        if ( procs[i].ifc[j].ip == id )
+                        {
+                                return( i );
+                        }
+                }
+	}
+	return( -1 );
+}
+
+static  void    Conf_config_copy( configuration *src_conf, configuration *dst_conf, proc *src_procs, proc *dst_procs)
+{
+    int i,j,p_index;
+
+    *dst_conf = *src_conf;
+
+    for (i=0; i < src_conf->num_total_procs; i++ )
+    {
+        dst_procs[i] = src_procs[i];
+    }
+
+    for (i=0; i < src_conf->num_segments; i++ )
+    {
+        for ( j=0; j < src_conf->segments[i].num_procs; j++ )
+        {
+            p_index = Conf_config_lookup_id(dst_conf, dst_procs, src_conf->segments[i].procs[j]->id);
+            assert(p_index != -1);
+            dst_conf->segments[i].procs[j] = &dst_procs[p_index];
+        }
+    }        
+
+#ifndef NDEBUG
+    /* Verify correct state after copy */
+    for (i=0; i < dst_conf->num_segments; i++ )
+    {
+        for ( j=0; j < dst_conf->segments[i].num_procs; j++ )
+        {
+            assert( dst_conf->segments[i].procs[j]->id == src_conf->segments[i].procs[j]->id );
+        }
+    }
+#endif
+}
+
 static  int     Conf_proc_ref_by_id( int32u id, proc **p )
 {
 	int	i,j;

Modified: trunk/daemon/network.c
===================================================================
--- trunk/daemon/network.c	2005-08-30 01:51:05 UTC (rev 272)
+++ trunk/daemon/network.c	2005-08-30 13:19:47 UTC (rev 273)
@@ -199,8 +199,8 @@
 	assert(my_next_index != -1);
 	for( i=0; i < Num_send_needed; i++ )
 		Alarm( NETWORK, 
-			"Net_set_membership: Send_addr[%d] is (%d,%d)\n",
-			i, Send_address[i], Send_ports[i] );
+			"Net_set_membership: Send_addr[%d] is (%u.%u.%u.%u:%d)\n",
+                       i, IP1(Send_address[i]), IP2(Send_address[i]), IP3(Send_address[i]), IP4(Send_address[i]), Send_ports[i] );
 
 	/* Calculate where to send the token */
 	Token_address = 0;
@@ -235,8 +235,8 @@
 		}
 
 	}
-	Alarm( NETWORK, "Net_set_membership: Token_address : (%d, %d)\n",
-			Token_address, Token_port );
+	Alarm( NETWORK, "Net_set_membership: Token_address : (%u.%u.%u.%u:%d)\n",
+               IP1(Token_address), IP2(Token_address), IP3(Token_address), IP4(Token_address), Token_port );
 }
 
 int	Net_bcast( sys_scatter *scat )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.