[sr-dev] git:ser_modules: cfg framework: fix the initialization of child processes

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Sep 17 21:06:29 CEST 2009


Module: sip-router
Branch: ser_modules
Commit: c76cffae64d8f1711f776de2bf23f64265b1a432
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c76cffae64d8f1711f776de2bf23f64265b1a432

Author: Miklos Tirpak <miklos at iptel.org>
Committer: Miklos Tirpak <miklos at iptel.org>
Date:   Thu Sep  3 09:56:18 2009 +0000

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.)

---

 modules_s/cpl-c/cpl.c         |    4 ++++
 modules_s/ctl/ctl.c           |    3 +++
 modules_s/fifo/fifo.c         |    8 +++++++-
 modules_s/jabber/jabber.c     |   11 +++++++++--
 modules_s/nathelper/natping.c |    7 +++++--
 modules_s/sms/sms.c           |    4 ++++
 6 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/modules_s/cpl-c/cpl.c b/modules_s/cpl-c/cpl.c
index 486cefd..82e1322 100644
--- a/modules_s/cpl-c/cpl.c
+++ b/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;
diff --git a/modules_s/ctl/ctl.c b/modules_s/ctl/ctl.c
index 071c2e2..d3fc9d8 100644
--- a/modules_s/ctl/ctl.c
+++ b/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();
diff --git a/modules_s/fifo/fifo.c b/modules_s/fifo/fifo.c
index 37b12ec..74d43cf 100644
--- a/modules_s/fifo/fifo.c
+++ b/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;
 }
 
diff --git a/modules_s/jabber/jabber.c b/modules_s/jabber/jabber.c
index d512447..7d00171 100644
--- a/modules_s/jabber/jabber.c
+++ b/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;
diff --git a/modules_s/nathelper/natping.c b/modules_s/nathelper/natping.c
index 27877d7..d802e44 100644
--- a/modules_s/nathelper/natping.c
+++ b/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)
diff --git a/modules_s/sms/sms.c b/modules_s/sms/sms.c
index d1832f4..c55247c 100644
--- a/modules_s/sms/sms.c
+++ b/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:




More information about the sr-dev mailing list