@@ -29,6 +29,7 @@ static void ngx_cache_loader_process_handler(ngx_event_t *ev);
2929
3030#if (NGX_HAVE_FSTACK )
3131extern int ff_mod_init (const char * conf , int proc_id , int proc_type );
32+ ngx_int_t ngx_ff_process ;
3233#endif
3334
3435ngx_uint_t ngx_process ;
@@ -72,7 +73,6 @@ static ngx_log_t ngx_exit_log;
7273static ngx_open_file_t ngx_exit_log_file ;
7374
7475#if (NGX_HAVE_FSTACK )
75- static ngx_int_t ngx_ff_primary ;
7676static sem_t * ngx_ff_worker_sem ;
7777#endif
7878
@@ -312,6 +312,51 @@ ngx_master_process_cycle(ngx_cycle_t *cycle)
312312 }
313313}
314314
315+ #if (NGX_HAVE_FSTACK )
316+ static int
317+ ngx_single_process_cycle_loop (void * arg )
318+ {
319+ ngx_uint_t i ;
320+ ngx_cycle_t * cycle = (ngx_cycle_t * )arg ;
321+
322+ //ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
323+
324+ ngx_process_events_and_timers (cycle );
325+
326+ if (ngx_terminate || ngx_quit ) {
327+
328+ for (i = 0 ; cycle -> modules [i ]; i ++ ) {
329+ if (cycle -> modules [i ]-> exit_process ) {
330+ cycle -> modules [i ]-> exit_process (cycle );
331+ }
332+ }
333+
334+ ngx_master_process_exit (cycle );
335+ }
336+
337+ if (ngx_reconfigure ) {
338+ ngx_reconfigure = 0 ;
339+ ngx_log_error (NGX_LOG_NOTICE , cycle -> log , 0 , "reconfiguring" );
340+
341+ cycle = ngx_init_cycle (cycle );
342+ if (cycle == NULL ) {
343+ cycle = (ngx_cycle_t * ) ngx_cycle ;
344+ return 0 ;
345+ }
346+
347+ ngx_cycle = cycle ;
348+ }
349+
350+ if (ngx_reopen ) {
351+ ngx_reopen = 0 ;
352+ ngx_log_error (NGX_LOG_NOTICE , cycle -> log , 0 , "reopening logs" );
353+ ngx_reopen_files (cycle , (ngx_uid_t ) - 1 );
354+ }
355+
356+ return 0 ;
357+ }
358+ #endif
359+
315360void
316361ngx_single_process_cycle (ngx_cycle_t * cycle )
317362{
@@ -322,6 +367,36 @@ ngx_single_process_cycle(ngx_cycle_t *cycle)
322367 exit (2 );
323368 }
324369
370+ #if (NGX_HAVE_FSTACK )
371+ ngx_core_conf_t * ccf ;
372+ ccf = (ngx_core_conf_t * ) ngx_get_conf (cycle -> conf_ctx , ngx_core_module );
373+ if (ccf -> fstack_conf .len == 0 ) {
374+ ngx_log_error (NGX_LOG_ALERT , cycle -> log , 0 ,
375+ "fstack_conf null" );
376+ exit (2 );
377+ }
378+
379+ ngx_ff_process = NGX_FF_PROCESS_PRIMARY ;
380+
381+ if (ff_mod_init ((const char * )ccf -> fstack_conf .data , 0 ,
382+ ngx_ff_process == NGX_FF_PROCESS_PRIMARY )) {
383+ ngx_log_error (NGX_LOG_ALERT , cycle -> log , 0 ,
384+ "ff_mod_init failed" );
385+ exit (2 );
386+ }
387+
388+ if (ngx_open_listening_sockets (cycle ) != NGX_OK ) {
389+ ngx_log_error (NGX_LOG_ALERT , cycle -> log , ngx_errno ,
390+ "ngx_open_listening_sockets failed" );
391+ exit (2 );
392+ }
393+
394+ if (!ngx_test_config ) {
395+ ngx_configure_listening_sockets (cycle );
396+ }
397+
398+ #endif
399+
325400 for (i = 0 ; cycle -> modules [i ]; i ++ ) {
326401 if (cycle -> modules [i ]-> init_process ) {
327402 if (cycle -> modules [i ]-> init_process (cycle ) == NGX_ERROR ) {
@@ -331,6 +406,9 @@ ngx_single_process_cycle(ngx_cycle_t *cycle)
331406 }
332407 }
333408
409+ #if (NGX_HAVE_FSTACK )
410+ ff_run (ngx_single_process_cycle_loop , (void * )cycle );
411+ #else
334412 for ( ;; ) {
335413 ngx_log_debug0 (NGX_LOG_DEBUG_EVENT , cycle -> log , 0 , "worker cycle" );
336414
@@ -366,6 +444,7 @@ ngx_single_process_cycle(ngx_cycle_t *cycle)
366444 ngx_reopen_files (cycle , (ngx_uid_t ) - 1 );
367445 }
368446 }
447+ #endif
369448}
370449
371450
@@ -1045,11 +1124,13 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
10451124 }
10461125
10471126 if (worker == 0 ) {
1048- ngx_ff_primary = 1 ;
1127+ ngx_ff_process = NGX_FF_PROCESS_PRIMARY ;
1128+ } else {
1129+ ngx_ff_process = NGX_FF_PROCESS_SECONDARY ;
10491130 }
10501131
10511132 if (ff_mod_init ((const char * )ccf -> fstack_conf .data , worker ,
1052- ngx_ff_primary )) {
1133+ ngx_ff_process == NGX_FF_PROCESS_PRIMARY )) {
10531134 ngx_log_error (NGX_LOG_ALERT , cycle -> log , 0 ,
10541135 "ff_mod_init failed" );
10551136 exit (2 );
@@ -1186,7 +1267,7 @@ ngx_worker_process_exit(ngx_cycle_t *cycle)
11861267 ngx_log_error (NGX_LOG_NOTICE , ngx_cycle -> log , 0 , "exit" );
11871268
11881269#if (NGX_HAVE_FSTACK )
1189- if (ngx_ff_primary ) {
1270+ if (ngx_ff_process == NGX_FF_PROCESS_PRIMARY ) {
11901271 // wait for secondary worker processes to exit.
11911272 ngx_msleep (500 );
11921273 }
0 commit comments