Skip to content

Commit 014d698

Browse files
author
chenwei
committed
Nginx: fixbug, support "master_process off".
1 parent 4c37281 commit 014d698

File tree

5 files changed

+96
-14
lines changed

5 files changed

+96
-14
lines changed

app/nginx-1.11.10/src/core/ngx_connection.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern int is_fstack_fd(int sockfd);
2222
static ngx_inline int
2323
ngx_ff_skip_listening_socket(ngx_cycle_t *cycle, const ngx_listening_t *ls, int *type)
2424
{
25-
if (ngx_process <= NGX_PROCESS_MASTER) {
25+
if (ngx_ff_process == NGX_FF_PROCESS_NONE) {
2626

2727
/* process master, kernel network stack*/
2828
if (!ls->belong_to_host) {
@@ -32,7 +32,7 @@ ngx_ff_skip_listening_socket(ngx_cycle_t *cycle, const ngx_listening_t *ls, int
3232
return 1;
3333
}
3434
}
35-
} else if (NGX_PROCESS_WORKER == ngx_process) {
35+
} else {
3636
/* process worker, fstack */
3737
if (ls->belong_to_host) {
3838
return 1;
@@ -45,11 +45,6 @@ ngx_ff_skip_listening_socket(ngx_cycle_t *cycle, const ngx_listening_t *ls, int
4545
if(type) {
4646
*type |= SOCK_FSTACK;
4747
}
48-
} else {
49-
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
50-
"unexpected process type: %d, ignored",
51-
ngx_process);
52-
exit(1);
5348
}
5449

5550
return 0;

app/nginx-1.11.10/src/event/modules/ngx_kqueue_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ ngx_kqueue_init(ngx_cycle_t *cycle, ngx_msec_t timer)
128128
#endif
129129

130130
#if (NGX_HAVE_FSTACK)
131-
if(ngx_process != NGX_PROCESS_WORKER) {
131+
if(ngx_ff_process == NGX_FF_PROCESS_NONE) {
132132
return NGX_OK;
133133
}
134134
#endif

app/nginx-1.11.10/src/event/ngx_event.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ ngx_process_events_and_timers(ngx_cycle_t *cycle)
252252

253253
#if (NGX_HAVE_FSTACK)
254254
/*
255-
* NGX_PROCESS_WORKERs run on both fstack and kernel,
255+
* NGX_FF_PROCESS_*s run on both fstack and kernel,
256256
* others ( e.g. cache manager/loader ) only run on kernel.
257257
*/
258-
if(ngx_process == NGX_PROCESS_WORKER) {
258+
if(!!ngx_ff_process) {
259259
(void) ngx_process_events(cycle, timer, flags);
260260

261261
/*

app/nginx-1.11.10/src/os/unix/ngx_process_cycle.c

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static void ngx_cache_loader_process_handler(ngx_event_t *ev);
2929

3030
#if (NGX_HAVE_FSTACK)
3131
extern int ff_mod_init(const char *conf, int proc_id, int proc_type);
32+
ngx_int_t ngx_ff_process;
3233
#endif
3334

3435
ngx_uint_t ngx_process;
@@ -72,7 +73,6 @@ static ngx_log_t ngx_exit_log;
7273
static ngx_open_file_t ngx_exit_log_file;
7374

7475
#if (NGX_HAVE_FSTACK)
75-
static ngx_int_t ngx_ff_primary;
7676
static 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+
315360
void
316361
ngx_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
}

app/nginx-1.11.10/src/os/unix/ngx_process_cycle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ typedef struct {
3737
void ngx_master_process_cycle(ngx_cycle_t *cycle);
3838
void ngx_single_process_cycle(ngx_cycle_t *cycle);
3939

40+
#if (NGX_HAVE_FSTACK)
41+
#define NGX_FF_PROCESS_NONE 0
42+
#define NGX_FF_PROCESS_PRIMARY 1
43+
#define NGX_FF_PROCESS_SECONDARY 2
44+
extern ngx_int_t ngx_ff_process;
45+
#endif
4046

4147
extern ngx_uint_t ngx_process;
4248
extern ngx_uint_t ngx_worker;

0 commit comments

Comments
 (0)