[sr-dev] git:master:6da946e4: core: keep a global flag in shm for shut down phase

Daniel-Constantin Mierla miconda at gmail.com
Mon Aug 10 16:24:48 CEST 2020


Module: kamailio
Branch: master
Commit: 6da946e4a3d6d6949dd6babe9cf3919edc0b4519
URL: https://github.com/kamailio/kamailio/commit/6da946e4a3d6d6949dd6babe9cf3919edc0b4519

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-08-10T16:15:04+02:00

core: keep a global flag in shm for shut down phase

- set when destroy modules is starting
- useful to check from other processes if shut down started

---

Modified: src/core/sr_module.c
Modified: src/core/sr_module.h
Modified: src/main.c

---

Diff:  https://github.com/kamailio/kamailio/commit/6da946e4a3d6d6949dd6babe9cf3919edc0b4519.diff
Patch: https://github.com/kamailio/kamailio/commit/6da946e4a3d6d6949dd6babe9cf3919edc0b4519.patch

---

diff --git a/src/core/sr_module.c b/src/core/sr_module.c
index 2c76ee2a1b..545845fdc5 100644
--- a/src/core/sr_module.c
+++ b/src/core/sr_module.c
@@ -109,6 +109,24 @@ unsigned int set_modinit_delay(unsigned int v)
 	return r;
 }
 
+/* shut down phase for instance - kept in shared memory */
+static int *_ksr_shutdown_phase = 0;
+
+int ksr_shutdown_phase_init(void)
+{
+	if(_ksr_shutdown_phase) {
+		_ksr_shutdown_phase = (int*)shm_malloc(sizeof(int));
+	}
+	return 0;
+}
+/**
+ * return destroy modules phase state
+ */
+int ksr_shutdown_phase(void)
+{
+	return (_ksr_shutdown_phase)?(*_ksr_shutdown_phase):0;
+}
+
 /* keep state if server is in destroy modules phase */
 static int _sr_destroy_modules_phase = 0;
 
@@ -738,6 +756,10 @@ void destroy_modules()
 	struct sr_module* t, *foo;
 
 	_sr_destroy_modules_phase = 1;
+	if(_ksr_shutdown_phase!=NULL) {
+		*_ksr_shutdown_phase = 1;
+	}
+
 	/* call first destroy function from each module */
 	t=modules;
 	while(t) {
diff --git a/src/core/sr_module.h b/src/core/sr_module.h
index 1f833a5e95..3014a88dad 100644
--- a/src/core/sr_module.h
+++ b/src/core/sr_module.h
@@ -544,5 +544,7 @@ int is_rpc_worker(int rank);
 
 unsigned int set_modinit_delay(unsigned int v);
 int destroy_modules_phase(void);
+int ksr_shutdown_phase_init(void);
+int ksr_shutdown_phase(void);
 
 #endif /* sr_module_h */
diff --git a/src/main.c b/src/main.c
index b2a2040631..9294bc3d94 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2542,6 +2542,8 @@ int main(int argc, char** argv)
 	if (ksr_route_locks_set_init()<0)
 		goto error;
 
+	ksr_shutdown_phase_init();
+
 	/* init lookup for core event routes */
 	sr_core_ert_init();
 




More information about the sr-dev mailing list