Skip to content

Commit

Permalink
Fix dont_fork mode.
Browse files Browse the repository at this point in the history
Closes #445.

(cherry picked from commit dbf2aec)
  • Loading branch information
bogdan-iancu committed Apr 14, 2015
1 parent 3459128 commit 1a1d72c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 44 deletions.
45 changes: 1 addition & 44 deletions main.c
Expand Up @@ -622,7 +622,6 @@ int install_sigs(void)
static int main_loop(void)
{
static int chd_rank;
int rc;
int* startup_done = NULL;

chd_rank=0;
Expand All @@ -639,19 +638,6 @@ static int main_loop(void)
goto error;
}

if (protos[PROTO_UDP].listeners==NULL){
LM_ERR("no fork mode requires at least one"
" udp listen address, exiting...\n");
goto error;
}
/* only one address, we ignore all the others */
// FIXME UDP
//if (udp_init(udp_listen)==-1) goto error;
bind_address=protos[PROTO_UDP].listeners;
if (protos[PROTO_UDP].listeners->next) {
LM_WARN("using only the first listen address (no fork)\n");
}

/* try to drop privileges */
if (do_suid(uid, gid)==-1)
goto error;
Expand All @@ -667,39 +653,10 @@ static int main_loop(void)
goto error;
}

/* main process, receive loop */
set_proc_attrs("stand-alone SIP receiver %.*s",
bind_address->sock_str.len, bind_address->sock_str.s );

/* We will call child_init even if we
* do not fork - and it will be called with rank 1 because
* in fact we behave like a child, not like main process */
if (init_child(1) < 0) {
LM_ERR("init_child failed in don't fork\n");
goto error;
}

if (startup_rlist.a)
run_startup_route();

is_main=1;

if (register_udp_load_stat(&protos[PROTO_UDP].listeners->sock_str,
&pt[process_no].load, 1)!=0) {
LM_ERR("failed to init udp load statistics\n");
goto error;
}

clean_write_pipeend();
LM_DBG("waiting for status code from children\n");
rc = wait_for_all_children();
if (rc < 0) {
LM_ERR("failed to succesfully init children\n");
return rc;
}
return udp_start_nofork();

// FIXME return udp_rcv_loop();
return -1;
} else { /* don't fork */

if (trans_init_all_listeners()<0) {
Expand Down
64 changes: 64 additions & 0 deletions net/net_udp.c
Expand Up @@ -306,6 +306,70 @@ int udp_rcv_loop( struct socket_info *si )
}


int udp_start_nofork(void)
{
struct socket_info *si;
stat_var *load_p = NULL;
int rc, p;

if (udp_disabled || (si=protos[PROTO_UDP].listeners)==NULL) {
LM_ERR("configuration error: no UDP listener in NO FORK mode\n");
return -1;
}

/* only one address, we ignore all the others */
if (si->next) {
LM_WARN("using only the first UDP listen address (no fork)\n");
}
for( p=PROTO_FIRST ; p<PROTO_LAST ; p++ )
if (p!=PROTO_UDP && protos[p].listeners)
LM_WARN("discarding all listen addresses for protocol %s\n",
protos[p].name);

if (udp_init_listener(si)<0) {
LM_ERR("failed to init the single UDP listener\n");
return -1;
}

if (register_udp_load_stat(&si->sock_str,&load_p,1/*children*/)!=0){
LM_ERR("failed to init load statistics\n");
return -1;
}
pt[process_no].load = load_p;

/* main process, receive loop */
set_proc_attrs("stand-alone SIP receiver %.*s",
si->sock_str.len, si->sock_str.s );

bind_address = si; /* shortcut */
protos[PROTO_UDP].sendipv4 = si;
protos[PROTO_UDP].sendipv6 = si; /*FIXME*/

/* We will call child_init even if we
* do not fork - and it will be called with rank 1 because
* in fact we behave like a child, not like main process */
if (init_child(1) < 0) {
LM_ERR("init_child failed in don't fork\n");
return -1;
}

if (startup_rlist.a)
run_startup_route();

is_main=1;

clean_write_pipeend();
LM_DBG("waiting for status code from children\n");
rc = wait_for_all_children();
if (rc < 0) {
LM_ERR("failed to succesfully init children\n");
return rc;
}

return udp_rcv_loop( si );
}


/* starts all UDP related processes */
int udp_start_processes(int *chd_rank, int *startup_done)
{
Expand Down
3 changes: 3 additions & 0 deletions net/net_udp.h
Expand Up @@ -40,6 +40,9 @@ void udp_destroy(void);
/* tells how mnay processes the UDP layer will create */
int udp_count_processes(void);

/* starts one UDP process for NO FORK mode */
int udp_start_nofork(void);

/* starts all UDP related processes */
int udp_start_processes(int *chd_rank, int *startup_done);

Expand Down

0 comments on commit 1a1d72c

Please sign in to comment.