From e7d81186b59b5e0681a099cc993365961b09752e Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Thu, 19 Oct 2017 17:43:54 +0300 Subject: Fixed controller restarting. Previously, stored configuration wasn't reread on controller process restart, which resulted in segmentation fault. --- src/nxt_main_process.c | 58 ++++++++++++++++++++++++++++++-------------------- src/nxt_process.h | 4 +++- 2 files changed, 38 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c index d6743b68..7d0050c4 100644 --- a/src/nxt_main_process.c +++ b/src/nxt_main_process.c @@ -25,6 +25,8 @@ static nxt_int_t nxt_main_process_port_create(nxt_task_t *task, static void nxt_main_process_title(nxt_task_t *task); static nxt_int_t nxt_main_start_controller_process(nxt_task_t *task, nxt_runtime_t *rt); +static nxt_int_t nxt_main_create_controller_process(nxt_task_t *task, + nxt_runtime_t *rt, nxt_process_init_t *init); static nxt_int_t nxt_main_start_router_process(nxt_task_t *task, nxt_runtime_t *rt); static nxt_int_t nxt_main_start_discovery_process(nxt_task_t *task, @@ -323,13 +325,36 @@ nxt_main_process_title(nxt_task_t *task) static nxt_int_t nxt_main_start_controller_process(nxt_task_t *task, nxt_runtime_t *rt) { - ssize_t n; - nxt_int_t ret; - nxt_str_t conf; - nxt_file_t file; - nxt_file_info_t fi; nxt_process_init_t *init; + init = nxt_malloc(sizeof(nxt_process_init_t)); + if (nxt_slow_path(init == NULL)) { + return NXT_ERROR; + } + + init->start = nxt_controller_start; + init->name = "controller"; + init->user_cred = &rt->user_cred; + init->port_handlers = &nxt_controller_process_port_handlers; + init->signals = nxt_worker_process_signals; + init->type = NXT_PROCESS_CONTROLLER; + init->stream = 0; + init->restart = &nxt_main_create_controller_process; + + return nxt_main_create_controller_process(task, rt, init);; +} + + +static nxt_int_t +nxt_main_create_controller_process(nxt_task_t *task, nxt_runtime_t *rt, + nxt_process_init_t *init) +{ + ssize_t n; + nxt_int_t ret; + nxt_str_t conf; + nxt_file_t file; + nxt_file_info_t fi; + conf.length = 0; nxt_memzero(&file, sizeof(nxt_file_t)); @@ -365,20 +390,7 @@ nxt_main_start_controller_process(nxt_task_t *task, nxt_runtime_t *rt) nxt_file_close(task, &file); } - init = nxt_malloc(sizeof(nxt_process_init_t)); - if (nxt_slow_path(init == NULL)) { - return NXT_ERROR; - } - - init->start = nxt_controller_start; - init->name = "controller"; - init->user_cred = &rt->user_cred; - init->port_handlers = &nxt_controller_process_port_handlers; - init->signals = nxt_worker_process_signals; - init->type = NXT_PROCESS_CONTROLLER; init->data = &conf; - init->stream = 0; - init->restart = 1; ret = nxt_main_create_worker_process(task, rt, init); @@ -408,7 +420,7 @@ nxt_main_start_discovery_process(nxt_task_t *task, nxt_runtime_t *rt) init->type = NXT_PROCESS_DISCOVERY; init->data = rt; init->stream = 0; - init->restart = 0; + init->restart = NULL; return nxt_main_create_worker_process(task, rt, init); } @@ -432,7 +444,7 @@ nxt_main_start_router_process(nxt_task_t *task, nxt_runtime_t *rt) init->type = NXT_PROCESS_ROUTER; init->data = rt; init->stream = 0; - init->restart = 1; + init->restart = &nxt_main_create_worker_process; return nxt_main_create_worker_process(task, rt, init); } @@ -494,7 +506,7 @@ nxt_main_start_worker_process(nxt_task_t *task, nxt_runtime_t *rt, init->type = NXT_PROCESS_WORKER; init->data = app_conf; init->stream = stream; - init->restart = 0; + init->restart = NULL; return nxt_main_create_worker_process(task, rt, init); } @@ -810,8 +822,8 @@ nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid) } } else if (init != NULL) { - if (init->restart != 0) { - (void) nxt_main_create_worker_process(task, rt, init); + if (init->restart != NULL) { + init->restart(task, rt, init); } else { nxt_free(init); diff --git a/src/nxt_process.h b/src/nxt_process.h index c2a011ef..1a36d9df 100644 --- a/src/nxt_process.h +++ b/src/nxt_process.h @@ -23,6 +23,8 @@ typedef struct { typedef struct nxt_process_init_s nxt_process_init_t; typedef nxt_int_t (*nxt_process_start_t)(nxt_task_t *task, void *data); +typedef nxt_int_t (*nxt_process_restart_t)(nxt_task_t *task, nxt_runtime_t *rt, + nxt_process_init_t *init); struct nxt_process_init_s { @@ -38,7 +40,7 @@ struct nxt_process_init_s { void *data; uint32_t stream; - nxt_bool_t restart; + nxt_process_restart_t restart; }; -- cgit