Module: kamailio
Branch: master
Commit: 4c57d02e53deda909cc93b41d613f62921c99a9c
URL:
https://github.com/kamailio/kamailio/commit/4c57d02e53deda909cc93b41d613f62…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-12-28T09:56:26+01:00
core: function to detect if all processes were forked
---
Modified: src/core/pt.h
Modified: src/main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/4c57d02e53deda909cc93b41d613f62…
Patch:
https://github.com/kamailio/kamailio/commit/4c57d02e53deda909cc93b41d613f62…
---
diff --git a/src/core/pt.h b/src/core/pt.h
index b6d4dc86fc..5c8ed49d99 100644
--- a/src/core/pt.h
+++ b/src/core/pt.h
@@ -96,4 +96,6 @@ int mem_dump_shm_fixup(void *handle, str *gname, str *name, void
**val);
unsigned int set_fork_delay(unsigned int v);
+int sr_instance_started(void);
+
#endif
diff --git a/src/main.c b/src/main.c
index aaf5637e53..08b6909278 100644
--- a/src/main.c
+++ b/src/main.c
@@ -499,6 +499,16 @@ char* pgid_file = 0;
char *sr_memmng_pkg = NULL;
char *sr_memmng_shm = NULL;
+static int *_sr_instance_started = NULL;
+
+int sr_instance_initialized(void)
+{
+ if(_sr_instance_started!=NULL && *_sr_instance_started==1) {
+ return 1;
+ }
+ return 0;
+}
+
/* call it before exiting; if show_status==1, mem status is displayed */
void cleanup(int show_status)
{
@@ -1253,6 +1263,14 @@ int main_loop(void)
int nrprocs;
int woneinit;
+ if(_sr_instance_started == NULL) {
+ _sr_instance_started = shm_malloc(sizeof(int));
+ if(_sr_instance_started == NULL) {
+ LM_ERR("no shared memory\n");
+ goto error;
+ }
+ *_sr_instance_started = 0;
+ }
/* one "main" process and n children handling i/o */
if (dont_fork){
#ifdef STATS
@@ -1415,6 +1433,7 @@ int main_loop(void)
LM_ERR("init_child failed\n");
goto error;
}
+ *_sr_instance_started = 1;
return udp_rcv_loop();
}else{ /* fork: */
@@ -1729,6 +1748,8 @@ int main_loop(void)
cfg_child_no_cb_init();
cfg_ok=1;
+ *_sr_instance_started = 1;
+
#ifdef EXTRA_DEBUG
for (r=0; r<*process_count; r++){
fprintf(stderr, "% 3d % 5d - %s\n", r, pt[r].pid, pt[r].desc);