Module: kamailio
Branch: master
Commit: 699d208adcae14565c1af289a9668aede5adaa72
URL: https://github.com/kamailio/kamailio/commit/699d208adcae14565c1af289a9668ae…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-03-15T12:29:08+01:00
core: global parameters to enable waiting for child one worker initialization
- new paramters:
- wait_child1_mode=[0|1] - set to wait or not
- wait_child1_time=1000000 (micro-seconds) - how long to wait over all
- wait_child1_usleep=100000 (micro-seconds) - step to wait before
checking if initialization completed
---
Modified: src/core/cfg.lex
Modified: src/core/cfg.y
Modified: src/core/globals.h
Modified: src/core/tcp_main.c
Modified: src/main.c
---
Diff: https://github.com/kamailio/kamailio/commit/699d208adcae14565c1af289a9668ae…
Patch: https://github.com/kamailio/kamailio/commit/699d208adcae14565c1af289a9668ae…
Module: kamailio
Branch: master
Commit: dc6d44b603b126c43757a53560d692e5f5f147a7
URL: https://github.com/kamailio/kamailio/commit/dc6d44b603b126c43757a53560d692e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-03-12T18:15:34+01:00
core: execute event_route[core:worker-one-init] for sctp or tcp
- if no udp worker is started, the event route is executed by next
available transport, in the order: sctp, tcp (or tls)
---
Modified: src/core/tcp_init.h
Modified: src/core/tcp_main.c
Modified: src/main.c
---
Diff: https://github.com/kamailio/kamailio/commit/dc6d44b603b126c43757a53560d692e…
Patch: https://github.com/kamailio/kamailio/commit/dc6d44b603b126c43757a53560d692e…
---
diff --git a/src/core/tcp_init.h b/src/core/tcp_init.h
index ddabbc5fce..70a193a0e2 100644
--- a/src/core/tcp_init.h
+++ b/src/core/tcp_init.h
@@ -13,8 +13,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -54,7 +54,7 @@ struct tcp_child{
int init_tcp(void);
void destroy_tcp(void);
int tcp_init(struct socket_info* sock_info);
-int tcp_init_children(void);
+int tcp_init_children(int *woneinit);
void tcp_main_loop(void);
void tcp_receive_loop(int unix_sock);
int tcp_fix_child_sockets(int* fd);
diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c
index aecf3a88c1..1fda94ec27 100644
--- a/src/core/tcp_main.c
+++ b/src/core/tcp_main.c
@@ -5034,16 +5034,16 @@ int tcp_fix_child_sockets(int* fd)
/* starts the tcp processes */
-int tcp_init_children()
+int tcp_init_children(int *woneinit)
{
int r, i;
int reader_fd_1; /* for comm. with the tcp children read */
pid_t pid;
char si_desc[MAX_PT_DESC];
struct socket_info *si;
-
+
/* estimate max fd. no:
- * 1 tcp send unix socket/all_proc,
+ * 1 tcp send unix socket/all_proc,
* + 1 udp sock/udp proc + 1 tcp_child sock/tcp child*
* + no_listen_tcp */
for(r=0, si=tcp_listen; si; si=si->next, r++);
@@ -5051,12 +5051,12 @@ int tcp_init_children()
if (! tls_disable)
for (si=tls_listen; si; si=si->next, r++);
#endif
-
+
register_fds(r+tcp_max_connections+get_max_procs()-1 /* tcp main */);
#if 0
tcp_max_fd_no=get_max_procs()*2 +r-1 /* timer */ +3; /* stdin/out/err*/
/* max connections can be temporarily exceeded with estimated_process_count
- * - tcp_main (tcpconn_connect called simultaneously in all all the
+ * - tcp_main (tcpconn_connect called simultaneously in all all the
* processes) */
tcp_max_fd_no+=tcp_max_connections+get_max_procs()-1 /* tcp main */;
#endif
@@ -5095,7 +5095,7 @@ int tcp_init_children()
/* create the tcp sock_info structures */
/* copy the sockets --moved to main_loop*/
-
+
/* fork children & create the socket pairs*/
for(r=0; r<tcp_children_no; r++){
child_rank++;
@@ -5108,10 +5108,16 @@ int tcp_init_children()
goto error;
}else if (pid>0){
/* parent */
+ *woneinit = 1;
}else{
/* child */
bind_address=0; /* force a SEGFAULT if someone uses a non-init.
bind address on tcp */
+ if(*woneinit==0) {
+ if(run_child_one_init_route()<0)
+ goto error;
+ }
+
tcp_receive_loop(reader_fd_1);
}
}
diff --git a/src/main.c b/src/main.c
index 6f8b354d22..e9d66ed449 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1720,8 +1720,14 @@ int main_loop(void)
/* child */
bind_address=si; /* shortcut */
+ if(woneinit==0) {
+ if(run_child_one_init_route()<0)
+ goto error;
+ }
+
return sctp_core_rcv_loop();
}
+ woneinit = 1;
}
/*parent*/
/*close(sctp_sock)*/; /*if closed=>sendto invalid fd errors?*/
@@ -1777,7 +1783,7 @@ int main_loop(void)
#ifdef USE_TCP
if (!tcp_disable){
/* start tcp & tls receivers */
- if (tcp_init_children()<0) goto error;
+ if (tcp_init_children(&woneinit)<0) goto error;
/* start tcp+tls main attendant proc */
pid = fork_process(PROC_TCP_MAIN, "tcp main process", 0);
if (pid<0){