Refactor of process management.
The process abstraction has changed to: setup(task, process) start(task, process_data) prefork(task, process, mp) The prefork() occurs in the main process right before fork. The file src/nxt_main_process.c is completely free of process specific logic. The creation of a process now supports a PROCESS_CREATED state. The The setup() function of each process can set its state to either created or ready. If created, a MSG_PROCESS_CREATED is sent to main process, where external setup can be done (required for rootfs under container). The core processes (discovery, controller and router) doesn't need external setup, then they all proceeds to their start() function straight away. In the case of applications, the load of the module happens at the process setup() time and The module's init() function has changed to be the start() of the process. The module API has changed to: setup(task, process, conf) start(task, data) As a direct benefit of the PROCESS_CREATED message, the clone(2) of processes using pid namespaces now doesn't need to create a pipe to make the child block until parent setup uid/gid mappings nor it needs to receive the child pid.
This commit is contained in:
@@ -21,6 +21,7 @@ static nxt_int_t nxt_runtime_thread_pools(nxt_thread_t *thr, nxt_runtime_t *rt);
|
||||
static void nxt_runtime_start(nxt_task_t *task, void *obj, void *data);
|
||||
static void nxt_runtime_initial_start(nxt_task_t *task, nxt_uint_t status);
|
||||
static void nxt_runtime_close_idle_connections(nxt_event_engine_t *engine);
|
||||
static void nxt_runtime_stop_all_processes(nxt_task_t *task, nxt_runtime_t *rt);
|
||||
static void nxt_runtime_exit(nxt_task_t *task, void *obj, void *data);
|
||||
static nxt_int_t nxt_runtime_event_engine_change(nxt_task_t *task,
|
||||
nxt_runtime_t *rt);
|
||||
@@ -438,7 +439,7 @@ nxt_runtime_quit(nxt_task_t *task, nxt_uint_t status)
|
||||
}
|
||||
|
||||
if (rt->type == NXT_PROCESS_MAIN) {
|
||||
nxt_main_stop_all_processes(task, rt);
|
||||
nxt_runtime_stop_all_processes(task, rt);
|
||||
done = 0;
|
||||
}
|
||||
}
|
||||
@@ -478,6 +479,50 @@ nxt_runtime_close_idle_connections(nxt_event_engine_t *engine)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nxt_runtime_stop_app_processes(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
{
|
||||
nxt_port_t *port;
|
||||
nxt_process_t *process;
|
||||
nxt_process_init_t *init;
|
||||
|
||||
nxt_runtime_process_each(rt, process) {
|
||||
|
||||
init = nxt_process_init(process);
|
||||
|
||||
if (init->type == NXT_PROCESS_APP) {
|
||||
|
||||
nxt_process_port_each(process, port) {
|
||||
|
||||
(void) nxt_port_socket_write(task, port, NXT_PORT_MSG_QUIT, -1,
|
||||
0, 0, NULL);
|
||||
|
||||
} nxt_process_port_loop;
|
||||
}
|
||||
|
||||
} nxt_runtime_process_loop;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nxt_runtime_stop_all_processes(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
{
|
||||
nxt_port_t *port;
|
||||
nxt_process_t *process;
|
||||
|
||||
nxt_runtime_process_each(rt, process) {
|
||||
|
||||
nxt_process_port_each(process, port) {
|
||||
|
||||
(void) nxt_port_socket_write(task, port, NXT_PORT_MSG_QUIT, -1, 0,
|
||||
0, NULL);
|
||||
|
||||
} nxt_process_port_loop;
|
||||
|
||||
} nxt_runtime_process_loop;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nxt_runtime_exit(nxt_task_t *task, void *obj, void *data)
|
||||
{
|
||||
@@ -525,6 +570,10 @@ nxt_runtime_exit(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
} nxt_runtime_process_loop;
|
||||
|
||||
if (rt->port_by_type[rt->type] != NULL) {
|
||||
nxt_port_use(task, rt->port_by_type[rt->type], -1);
|
||||
}
|
||||
|
||||
nxt_thread_mutex_destroy(&rt->processes_mutex);
|
||||
|
||||
status = rt->status;
|
||||
@@ -1306,7 +1355,9 @@ nxt_runtime_process_new(nxt_runtime_t *rt)
|
||||
|
||||
/* TODO: memory failures. */
|
||||
|
||||
process = nxt_mp_zalloc(rt->mem_pool, sizeof(nxt_process_t));
|
||||
process = nxt_mp_zalloc(rt->mem_pool,
|
||||
sizeof(nxt_process_t) + sizeof(nxt_process_init_t));
|
||||
|
||||
if (nxt_slow_path(process == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -1347,8 +1398,9 @@ nxt_runtime_process_release(nxt_runtime_t *rt, nxt_process_t *process)
|
||||
nxt_thread_mutex_destroy(&process->outgoing.mutex);
|
||||
nxt_thread_mutex_destroy(&process->cp_mutex);
|
||||
|
||||
if (process->init != NULL) {
|
||||
nxt_mp_destroy(process->init->mem_pool);
|
||||
/* processes from nxt_runtime_process_get() have no memory pool */
|
||||
if (process->mem_pool != NULL) {
|
||||
nxt_mp_destroy(process->mem_pool);
|
||||
}
|
||||
|
||||
nxt_mp_free(rt->mem_pool, process);
|
||||
|
||||
Reference in New Issue
Block a user