Преглед изворни кода

cfg framework: fix the initialization of child processes
(backport from sip-router)

The number of child processes that keep updating their
local configuration needs to be known before any child
process is forked.
Before this the child processes increased the reference
counter of the callback function list items after forking.
If a child process was forked "too fast" then it freed the list
before the other processes had a chance to refer to the list
item. The result was that some child processes missed
the initial configuration changes. (Those changes that
had per-child process callback defined.)

Miklos Tirpak пре 16 година
родитељ
комит
c76cffae64

+ 4 - 0
modules_s/cpl-c/cpl.c

@@ -375,6 +375,10 @@ static int cpl_init(void)
 		strlower( &cpl_env.realm_prefix );
 	}
 
+	/* Register a child process that will keep updating
+	 * its local configuration */
+	cfg_register_child(1);
+
 	return 0;
 error:
 	return -1;

+ 3 - 0
modules_s/ctl/ctl.c

@@ -36,6 +36,7 @@
 #include "../../ut.h"
 #include "../../dprint.h"
 #include "../../pt.h"
+#include "../../cfg/cfg_struct.h"
 #include "ctrl_socks.h"
 #include "io_listener.h"
 
@@ -265,6 +266,8 @@ static int mod_init(void)
 		/* we will fork */
 		register_procs(1); /* we will be creating an extra process */
 		register_fds(fd_no);
+		/* The child process will keep updating its local configuration */
+		cfg_register_child(1);
 	}
 #ifdef USE_FIFO
 	fifo_rpc_init();

+ 7 - 1
modules_s/fifo/fifo.c

@@ -33,6 +33,7 @@
 #include "../../ut.h"
 #include "../../dprint.h"
 #include "../../pt.h"
+#include "../../cfg/cfg_struct.h"
 #include "fifo_server.h"
 #include "fifo.h"
 
@@ -82,7 +83,12 @@ static int mod_init(void)
 	     /* Signal to the core that we will be creating one
 	      * additional process
 	      */
-	if (fifo) register_procs(1);
+	if (fifo) {
+		register_procs(1);
+		/* The child process will keep updating its
+		 * local configuration */
+		cfg_register_child(1);
+	}
 	return 0;
 }
 

+ 9 - 2
modules_s/jabber/jabber.c

@@ -280,6 +280,10 @@ static int mod_init(void)
 		return -1;
 	}
 
+	/* register nrw + 1 number of children that will keep
+	 * updating their local configuration */
+	cfg_register_child(nrw + 1);
+
 	DBG("XJAB:mod_init: initialized ...\n");
 	return 0;
 }
@@ -850,8 +854,11 @@ void xjab_check_workers(int mpid)
 			}
 
 
-			/* initialize the config framework */
-			if (cfg_child_init()) return;
+			/* initialize the config framework
+			 * The child process was not registered under
+			 * the framework during mod_init, therefore the
+			 * late version needs to be called. (Miklos) */
+			if (cfg_late_child_init()) return;
 
 			ctx = db_ctx("jabber");
 			if (ctx == NULL) goto dberror;

+ 5 - 2
modules_s/nathelper/natping.c

@@ -109,10 +109,13 @@ natpinger_init(void)
 		 * Use timer only in single process. For forked SER,
 		 * use separate process (see natpinger_child_init())
 		 */
-		if (dont_fork)
+		if (dont_fork) {
 			register_timer(natping, NULL, natping_interval);
-		else
+		} else {
 			register_procs(1); /* register the separate natpinger process */
+			/* The process will keep updating its configuration */
+			cfg_register_child(1);
+		}
 
 		if (natping_method == NULL) {
 			if (natping_crlf == 0)

+ 4 - 0
modules_s/sms/sms.c

@@ -628,6 +628,10 @@ int global_init()
 		goto error;
 	}
 	*queued_msgs = 0;
+	
+	/* register nr_of_modems number of child processes that will
+	 * update their local configuration */
+	cfg_register_child(nr_of_modems);
 
 	return 1;
 error: