Skip to content

Commit

Permalink
core: function to detect if all processes were forked
Browse files Browse the repository at this point in the history
(cherry picked from commit 4c57d02)
  • Loading branch information
miconda committed Jan 7, 2019
1 parent f62c3cb commit 260aa34
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/pt.h
Expand Up @@ -98,4 +98,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
21 changes: 21 additions & 0 deletions src/main.c
Expand Up @@ -505,6 +505,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)
{
Expand Down Expand Up @@ -1260,6 +1270,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
Expand Down Expand Up @@ -1422,6 +1440,7 @@ int main_loop(void)
LM_ERR("init_child failed\n");
goto error;
}
*_sr_instance_started = 1;
return udp_rcv_loop();
}else{ /* fork: */

Expand Down Expand Up @@ -1736,6 +1755,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);
Expand Down

0 comments on commit 260aa34

Please sign in to comment.