Module: sip-router
Branch: master
Commit: f6d530e68ffe9db11f5f148c51f8bff0b542f028
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f6d530e…
Author: Jason Penton <jason.penton(a)smilecoms.com>
Committer: Jason Penton <jason.penton(a)smilecoms.com>
Date: Tue Oct 22 20:57:52 2013 +0200
modules/cdp: allow CDP child processes to respond to dynamic cfg changes
- this for example allows dumping pkg memory using core cfg variables similar to SIP
workers, etc
---
modules/cdp/diameter_peer.c | 7 +++++++
modules/cdp/mod.c | 3 +++
modules/cdp/receiver.c | 3 +++
modules/cdp/tcp_accept.c | 4 ++++
modules/cdp/timer.c | 3 +++
modules/cdp/worker.c | 3 +++
6 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/modules/cdp/diameter_peer.c b/modules/cdp/diameter_peer.c
index ce86e1a..6bb5da2 100644
--- a/modules/cdp/diameter_peer.c
+++ b/modules/cdp/diameter_peer.c
@@ -62,6 +62,7 @@
#include "session.h"
#include "../../pt.h"
+#include "../../cfg/cfg_struct.h"
dp_config *config=0; /**< Configuration for this diameter peer */
@@ -304,6 +305,7 @@ int diameter_peer_start(int blocking)
if (pid==0) {
srandom(time(0)*k);
snprintf(pt[process_no].desc, MAX_PT_DESC,"cdp worker child=%d", k );
+ if (cfg_child_init()) return 0;
worker_process(k);
LM_CRIT("init_diameter_peer(): worker_process finished without exit!\n");
exit(-1);
@@ -330,6 +332,7 @@ int diameter_peer_start(int blocking)
srandom(time(0)*k);
snprintf(pt[process_no].desc, MAX_PT_DESC,
"cdp receiver peer unknown");
+ if (cfg_child_init()) return 0;
receiver_process(NULL);
LM_CRIT("init_diameter_peer(): receiver_process finished without exit!\n");
exit(-1);
@@ -349,6 +352,7 @@ int diameter_peer_start(int blocking)
srandom(time(0)*k);
snprintf(pt[process_no].desc, MAX_PT_DESC,
"cdp_receiver_peer=%.*s", p->fqdn.len,p->fqdn.s );
+ if (cfg_child_init()) return 0;
receiver_process(p);
LM_CRIT("init_diameter_peer(): receiver_process finished without exit!\n");
exit(-1);
@@ -367,6 +371,7 @@ int diameter_peer_start(int blocking)
return 0;
}
if (pid==0) {
+ if (cfg_child_init()) return 0;
acceptor_process(config);
LM_CRIT("init_diameter_peer(): acceptor_process finished without exit!\n");
exit(-1);
@@ -377,6 +382,7 @@ int diameter_peer_start(int blocking)
/* fork/become timer */
if (blocking) {
dp_add_pid(getpid());
+ if (cfg_child_init()) return 0;
timer_process(1);
}
else{
@@ -386,6 +392,7 @@ int diameter_peer_start(int blocking)
return 0;
}
if (pid==0) {
+ if (cfg_child_init()) return 0;
timer_process(0);
LM_CRIT("init_diameter_peer(): timer_process finished without exit!\n");
exit(-1);
diff --git a/modules/cdp/mod.c b/modules/cdp/mod.c
index 258a710..0f12b4c 100644
--- a/modules/cdp/mod.c
+++ b/modules/cdp/mod.c
@@ -52,6 +52,8 @@
#include "config.h"
#include "cdp_load.h"
+#include "../../cfg/cfg_struct.h"
+
MODULE_VERSION
char* config_file="DiameterPeer.xml"; /**< default DiameterPeer
configuration filename */
@@ -219,6 +221,7 @@ static int cdp_init( void )
return 1;
}
register_procs(2+config->workers + 2 * config->peers_cnt);
+ cfg_register_child(2+config->workers + 2 * config->peers_cnt);
return 0;
}
diff --git a/modules/cdp/receiver.c b/modules/cdp/receiver.c
index 538b233..5762694 100644
--- a/modules/cdp/receiver.c
+++ b/modules/cdp/receiver.c
@@ -69,6 +69,8 @@
#include "receiver.h"
+#include "../../cfg/cfg_struct.h"
+
extern dp_config *config; /**< Configuration for this diameter peer */
int dp_add_pid(pid_t pid);
@@ -643,6 +645,7 @@ int receive_loop(peer *original_peer)
while(!n){
if (shutdownx&&*shutdownx) break;
+ cfg_update();
log_serviced_peers();
diff --git a/modules/cdp/tcp_accept.c b/modules/cdp/tcp_accept.c
index fdf3dd3..473f14b 100644
--- a/modules/cdp/tcp_accept.c
+++ b/modules/cdp/tcp_accept.c
@@ -63,6 +63,8 @@
#include "tcp_accept.h"
#include "receiver.h"
+#include "../../cfg/cfg_struct.h"
+
/* defined in ../diameter_peer.c */
int dp_add_pid(pid_t pid);
@@ -205,6 +207,8 @@ void accept_loop()
while(1){
if (shutdownx && *shutdownx) break;
+ cfg_update();
+
timeout.tv_sec=2;
timeout.tv_usec=0;
FD_ZERO(&listen_set);
diff --git a/modules/cdp/timer.c b/modules/cdp/timer.c
index 0ac18c5..17be7de 100644
--- a/modules/cdp/timer.c
+++ b/modules/cdp/timer.c
@@ -53,6 +53,8 @@
#include "timer.h"
+#include "../../cfg/cfg_struct.h"
+
/* defined in ../diameter_peer.c */
int dp_add_pid(pid_t pid);
@@ -83,6 +85,7 @@ void timer_loop()
while(1){
if (shutdownx && *shutdownx) break;
now = time(0);
+ cfg_update();
do {
cb = 0;
diff --git a/modules/cdp/worker.c b/modules/cdp/worker.c
index b4d4fb9..45cffe6 100644
--- a/modules/cdp/worker.c
+++ b/modules/cdp/worker.c
@@ -57,6 +57,8 @@
#include "worker.h"
#include "diameter_api.h"
+#include "../../cfg/cfg_struct.h"
+
/* defined in ../diameter_peer.c */
int dp_add_pid(pid_t pid);
void dp_del_pid(pid_t pid);
@@ -315,6 +317,7 @@ void worker_process(int id) {
/* init the application level for this child */
while (1) {
if (shutdownx && (*shutdownx)) break;
+ cfg_update();
t = take_task();
if (!t.msg) {
if (shutdownx && (*shutdownx)) break;