@@ -2158,7 +2158,7 @@ int tcp_count_processes(unsigned int *extra)
21582158}
21592159
21602160
2161- int tcp_start_processes (int * chd_rank , int * startup_done )
2161+ int tcp_start_processes (int * chd_rank , atomic_t * startup_done )
21622162{
21632163 int r , n , p_id ;
21642164 int reader_fd [2 ]; /* for comm. with the tcp workers read */
@@ -2209,6 +2209,15 @@ int tcp_start_processes(int *chd_rank, int *startup_done)
22092209 tcp_workers [r ].state = STATE_ACTIVE ;
22102210 tcp_workers [r ].n_reqs = 0 ;
22112211 tcp_workers [r ].pt_idx = p_id ;
2212+ /* Wait for the startup owner before forking more workers. */
2213+ if (* chd_rank == 1 && startup_done ) {
2214+ while (atomic_load (startup_done ) == 0 ) {
2215+ usleep (5 );
2216+ handle_sigs ();
2217+ }
2218+ if (atomic_load (startup_done ) != 1 )
2219+ goto error ;
2220+ }
22122221 }else {
22132222 /* child */
22142223 set_proc_attrs ("TCP receiver" );
@@ -2217,21 +2226,22 @@ int tcp_start_processes(int *chd_rank, int *startup_done)
22172226 init_child (* chd_rank ) < 0 ) {
22182227 LM_ERR ("init_children failed\n" );
22192228 report_failure_status ();
2220- if (startup_done )
2221- * startup_done = -1 ;
2229+ if (* chd_rank == 1 && startup_done )
2230+ atomic_store ( startup_done , -1 ) ;
22222231 exit (-1 );
22232232 }
22242233
2225- /* was startup route executed so far ? */
2226- if (startup_done != NULL && * startup_done == 0 && r == 0 ) {
2227- LM_DBG ("running startup for first TCP\n" );
2228- if (run_startup_route ()< 0 ) {
2229- LM_ERR ("Startup route processing failed\n" );
2234+ /* Only the first SIP worker owns the startup flag. In a mixed
2235+ * setup the first UDP worker has already run the startup route. */
2236+ if (* chd_rank == 1 && startup_done ) {
2237+ LM_DBG ("running startup route for first TCP worker\n" );
2238+ if (run_startup_route () < 0 ) {
2239+ LM_ERR ("startup route processing failed in TCP worker\n" );
22302240 report_failure_status ();
2231- * startup_done = -1 ;
2241+ atomic_store ( startup_done , -1 ) ;
22322242 exit (-1 );
22332243 }
2234- * startup_done = 1 ;
2244+ atomic_store ( startup_done , 1 ) ;
22352245 }
22362246
22372247 report_conditional_status ( (!no_daemon_mode ), 0 );
@@ -2240,13 +2250,6 @@ int tcp_start_processes(int *chd_rank, int *startup_done)
22402250 }
22412251 }
22422252
2243- /* wait for the startup route to be executed */
2244- if (startup_done )
2245- while (!(* startup_done )) {
2246- usleep (5 );
2247- handle_sigs ();
2248- }
2249-
22502253 return 0 ;
22512254error :
22522255 return -1 ;
0 commit comments