@@ -29,6 +29,7 @@ static void ngx_cache_loader_process_handler(ngx_event_t *ev);
29
29
30
30
#if (NGX_HAVE_FSTACK )
31
31
extern int ff_mod_init (const char * conf , int proc_id , int proc_type );
32
+ ngx_int_t ngx_ff_process ;
32
33
#endif
33
34
34
35
ngx_uint_t ngx_process ;
@@ -72,7 +73,6 @@ static ngx_log_t ngx_exit_log;
72
73
static ngx_open_file_t ngx_exit_log_file ;
73
74
74
75
#if (NGX_HAVE_FSTACK )
75
- static ngx_int_t ngx_ff_primary ;
76
76
static sem_t * ngx_ff_worker_sem ;
77
77
#endif
78
78
@@ -312,6 +312,51 @@ ngx_master_process_cycle(ngx_cycle_t *cycle)
312
312
}
313
313
}
314
314
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
+
315
360
void
316
361
ngx_single_process_cycle (ngx_cycle_t * cycle )
317
362
{
@@ -322,6 +367,36 @@ ngx_single_process_cycle(ngx_cycle_t *cycle)
322
367
exit (2 );
323
368
}
324
369
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
+
325
400
for (i = 0 ; cycle -> modules [i ]; i ++ ) {
326
401
if (cycle -> modules [i ]-> init_process ) {
327
402
if (cycle -> modules [i ]-> init_process (cycle ) == NGX_ERROR ) {
@@ -331,6 +406,9 @@ ngx_single_process_cycle(ngx_cycle_t *cycle)
331
406
}
332
407
}
333
408
409
+ #if (NGX_HAVE_FSTACK )
410
+ ff_run (ngx_single_process_cycle_loop , (void * )cycle );
411
+ #else
334
412
for ( ;; ) {
335
413
ngx_log_debug0 (NGX_LOG_DEBUG_EVENT , cycle -> log , 0 , "worker cycle" );
336
414
@@ -366,6 +444,7 @@ ngx_single_process_cycle(ngx_cycle_t *cycle)
366
444
ngx_reopen_files (cycle , (ngx_uid_t ) - 1 );
367
445
}
368
446
}
447
+ #endif
369
448
}
370
449
371
450
@@ -1045,11 +1124,13 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
1045
1124
}
1046
1125
1047
1126
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 ;
1049
1130
}
1050
1131
1051
1132
if (ff_mod_init ((const char * )ccf -> fstack_conf .data , worker ,
1052
- ngx_ff_primary )) {
1133
+ ngx_ff_process == NGX_FF_PROCESS_PRIMARY )) {
1053
1134
ngx_log_error (NGX_LOG_ALERT , cycle -> log , 0 ,
1054
1135
"ff_mod_init failed" );
1055
1136
exit (2 );
@@ -1186,7 +1267,7 @@ ngx_worker_process_exit(ngx_cycle_t *cycle)
1186
1267
ngx_log_error (NGX_LOG_NOTICE , ngx_cycle -> log , 0 , "exit" );
1187
1268
1188
1269
#if (NGX_HAVE_FSTACK )
1189
- if (ngx_ff_primary ) {
1270
+ if (ngx_ff_process == NGX_FF_PROCESS_PRIMARY ) {
1190
1271
// wait for secondary worker processes to exit.
1191
1272
ngx_msleep (500 );
1192
1273
}
0 commit comments