Skip to content

Commit

Permalink
Fix init of UDP listener in nofork mode.
Browse files Browse the repository at this point in the history
Init the UDP listener before forking the MI procs, otherwise they will not be aware of the network sockets.
Closes #541
Self reported.
  • Loading branch information
bogdan-iancu committed Jun 4, 2015
1 parent fd8036c commit c146594
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion main.c
Expand Up @@ -641,7 +641,12 @@ static int main_loop(void)
if (dont_fork){

if (create_status_pipe() < 0) {
LM_ERR("failed to create status pipe");
LM_ERR("failed to create status pipe\n");
goto error;
}

if (udp_init_nofork() < 0) {
LM_ERR("failed to init UDP for no fork mode\n");
goto error;
}

Expand Down
21 changes: 17 additions & 4 deletions net/net_udp.c
Expand Up @@ -312,11 +312,11 @@ int udp_rcv_loop( struct socket_info *si )
}


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

if (udp_disabled || (si=protos[PROTO_UDP].listeners)==NULL) {
LM_ERR("configuration error: no UDP listener in NO FORK mode\n");
Expand All @@ -337,19 +337,32 @@ int udp_start_nofork(void)
return -1;
}

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

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;

return 0;
}


int udp_start_nofork(void)
{
struct socket_info *si;
int rc;

/* this was tested by udp_init_nofork !!! */
si = protos[PROTO_UDP].listeners;

/* 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
Expand Down
1 change: 1 addition & 0 deletions net/net_udp.h
Expand Up @@ -41,6 +41,7 @@ void udp_destroy(void);
int udp_count_processes(void);

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

/* starts all UDP related processes */
Expand Down

0 comments on commit c146594

Please sign in to comment.