nxt_runtime.c (1487:6238e2224c43) nxt_runtime.c (1488:6976d36be926)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_main.h>

--- 7 unchanged lines hidden (view full) ---

16 nxt_runtime_t *rt);
17static nxt_int_t nxt_runtime_systemd_listen_sockets(nxt_task_t *task,
18 nxt_runtime_t *rt);
19static nxt_int_t nxt_runtime_event_engines(nxt_task_t *task, nxt_runtime_t *rt);
20static nxt_int_t nxt_runtime_thread_pools(nxt_thread_t *thr, nxt_runtime_t *rt);
21static void nxt_runtime_start(nxt_task_t *task, void *obj, void *data);
22static void nxt_runtime_initial_start(nxt_task_t *task, nxt_uint_t status);
23static void nxt_runtime_close_idle_connections(nxt_event_engine_t *engine);
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_main.h>

--- 7 unchanged lines hidden (view full) ---

16 nxt_runtime_t *rt);
17static nxt_int_t nxt_runtime_systemd_listen_sockets(nxt_task_t *task,
18 nxt_runtime_t *rt);
19static nxt_int_t nxt_runtime_event_engines(nxt_task_t *task, nxt_runtime_t *rt);
20static nxt_int_t nxt_runtime_thread_pools(nxt_thread_t *thr, nxt_runtime_t *rt);
21static void nxt_runtime_start(nxt_task_t *task, void *obj, void *data);
22static void nxt_runtime_initial_start(nxt_task_t *task, nxt_uint_t status);
23static void nxt_runtime_close_idle_connections(nxt_event_engine_t *engine);
24static void nxt_runtime_stop_all_processes(nxt_task_t *task, nxt_runtime_t *rt);
24static void nxt_runtime_exit(nxt_task_t *task, void *obj, void *data);
25static nxt_int_t nxt_runtime_event_engine_change(nxt_task_t *task,
26 nxt_runtime_t *rt);
27static nxt_int_t nxt_runtime_conf_init(nxt_task_t *task, nxt_runtime_t *rt);
28static nxt_int_t nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt);
29static nxt_int_t nxt_runtime_hostname(nxt_task_t *task, nxt_runtime_t *rt);
30static nxt_int_t nxt_runtime_log_files_init(nxt_runtime_t *rt);
31static nxt_int_t nxt_runtime_log_files_create(nxt_task_t *task,

--- 401 unchanged lines hidden (view full) ---

433 engine->shutdown = 1;
434
435 if (!nxt_array_is_empty(rt->thread_pools)) {
436 nxt_runtime_thread_pool_destroy(task, rt, nxt_runtime_quit);
437 done = 0;
438 }
439
440 if (rt->type == NXT_PROCESS_MAIN) {
25static void nxt_runtime_exit(nxt_task_t *task, void *obj, void *data);
26static nxt_int_t nxt_runtime_event_engine_change(nxt_task_t *task,
27 nxt_runtime_t *rt);
28static nxt_int_t nxt_runtime_conf_init(nxt_task_t *task, nxt_runtime_t *rt);
29static nxt_int_t nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt);
30static nxt_int_t nxt_runtime_hostname(nxt_task_t *task, nxt_runtime_t *rt);
31static nxt_int_t nxt_runtime_log_files_init(nxt_runtime_t *rt);
32static nxt_int_t nxt_runtime_log_files_create(nxt_task_t *task,

--- 401 unchanged lines hidden (view full) ---

434 engine->shutdown = 1;
435
436 if (!nxt_array_is_empty(rt->thread_pools)) {
437 nxt_runtime_thread_pool_destroy(task, rt, nxt_runtime_quit);
438 done = 0;
439 }
440
441 if (rt->type == NXT_PROCESS_MAIN) {
441 nxt_main_stop_all_processes(task, rt);
442 nxt_runtime_stop_all_processes(task, rt);
442 done = 0;
443 }
444 }
445
446 nxt_runtime_close_idle_connections(engine);
447
448 if (done) {
449 nxt_work_queue_add(&engine->fast_work_queue, nxt_runtime_exit,

--- 23 unchanged lines hidden (view full) ---

473 if (!c->socket.read_ready) {
474 nxt_queue_remove(link);
475 nxt_conn_close(engine, c);
476 }
477 }
478}
479
480
443 done = 0;
444 }
445 }
446
447 nxt_runtime_close_idle_connections(engine);
448
449 if (done) {
450 nxt_work_queue_add(&engine->fast_work_queue, nxt_runtime_exit,

--- 23 unchanged lines hidden (view full) ---

474 if (!c->socket.read_ready) {
475 nxt_queue_remove(link);
476 nxt_conn_close(engine, c);
477 }
478 }
479}
480
481
482void
483nxt_runtime_stop_app_processes(nxt_task_t *task, nxt_runtime_t *rt)
484{
485 nxt_port_t *port;
486 nxt_process_t *process;
487 nxt_process_init_t *init;
488
489 nxt_runtime_process_each(rt, process) {
490
491 init = nxt_process_init(process);
492
493 if (init->type == NXT_PROCESS_APP) {
494
495 nxt_process_port_each(process, port) {
496
497 (void) nxt_port_socket_write(task, port, NXT_PORT_MSG_QUIT, -1,
498 0, 0, NULL);
499
500 } nxt_process_port_loop;
501 }
502
503 } nxt_runtime_process_loop;
504}
505
506
481static void
507static void
508nxt_runtime_stop_all_processes(nxt_task_t *task, nxt_runtime_t *rt)
509{
510 nxt_port_t *port;
511 nxt_process_t *process;
512
513 nxt_runtime_process_each(rt, process) {
514
515 nxt_process_port_each(process, port) {
516
517 (void) nxt_port_socket_write(task, port, NXT_PORT_MSG_QUIT, -1, 0,
518 0, NULL);
519
520 } nxt_process_port_loop;
521
522 } nxt_runtime_process_loop;
523}
524
525
526static void
482nxt_runtime_exit(nxt_task_t *task, void *obj, void *data)
483{
484 int status;
485 nxt_runtime_t *rt;
486 nxt_process_t *process;
487 nxt_event_engine_t *engine;
488
489 rt = obj;

--- 30 unchanged lines hidden (view full) ---

520 }
521
522 nxt_runtime_process_each(rt, process) {
523
524 nxt_process_close_ports(task, process);
525
526 } nxt_runtime_process_loop;
527
527nxt_runtime_exit(nxt_task_t *task, void *obj, void *data)
528{
529 int status;
530 nxt_runtime_t *rt;
531 nxt_process_t *process;
532 nxt_event_engine_t *engine;
533
534 rt = obj;

--- 30 unchanged lines hidden (view full) ---

565 }
566
567 nxt_runtime_process_each(rt, process) {
568
569 nxt_process_close_ports(task, process);
570
571 } nxt_runtime_process_loop;
572
573 if (rt->port_by_type[rt->type] != NULL) {
574 nxt_port_use(task, rt->port_by_type[rt->type], -1);
575 }
576
528 nxt_thread_mutex_destroy(&rt->processes_mutex);
529
530 status = rt->status;
531 nxt_mp_destroy(rt->mem_pool);
532
533 nxt_debug(task, "exit: %d", status);
534
535 exit(status);

--- 765 unchanged lines hidden (view full) ---

1301
1302nxt_process_t *
1303nxt_runtime_process_new(nxt_runtime_t *rt)
1304{
1305 nxt_process_t *process;
1306
1307 /* TODO: memory failures. */
1308
577 nxt_thread_mutex_destroy(&rt->processes_mutex);
578
579 status = rt->status;
580 nxt_mp_destroy(rt->mem_pool);
581
582 nxt_debug(task, "exit: %d", status);
583
584 exit(status);

--- 765 unchanged lines hidden (view full) ---

1350
1351nxt_process_t *
1352nxt_runtime_process_new(nxt_runtime_t *rt)
1353{
1354 nxt_process_t *process;
1355
1356 /* TODO: memory failures. */
1357
1309 process = nxt_mp_zalloc(rt->mem_pool, sizeof(nxt_process_t));
1358 process = nxt_mp_zalloc(rt->mem_pool,
1359 sizeof(nxt_process_t) + sizeof(nxt_process_init_t));
1360
1310 if (nxt_slow_path(process == NULL)) {
1311 return NULL;
1312 }
1313
1314 nxt_queue_init(&process->ports);
1315
1316 nxt_thread_mutex_create(&process->incoming.mutex);
1317 nxt_thread_mutex_create(&process->outgoing.mutex);

--- 24 unchanged lines hidden (view full) ---

1342 port = nxt_port_hash_retrieve(&process->connected_ports);
1343
1344 } while (port != NULL);
1345
1346 nxt_thread_mutex_destroy(&process->incoming.mutex);
1347 nxt_thread_mutex_destroy(&process->outgoing.mutex);
1348 nxt_thread_mutex_destroy(&process->cp_mutex);
1349
1361 if (nxt_slow_path(process == NULL)) {
1362 return NULL;
1363 }
1364
1365 nxt_queue_init(&process->ports);
1366
1367 nxt_thread_mutex_create(&process->incoming.mutex);
1368 nxt_thread_mutex_create(&process->outgoing.mutex);

--- 24 unchanged lines hidden (view full) ---

1393 port = nxt_port_hash_retrieve(&process->connected_ports);
1394
1395 } while (port != NULL);
1396
1397 nxt_thread_mutex_destroy(&process->incoming.mutex);
1398 nxt_thread_mutex_destroy(&process->outgoing.mutex);
1399 nxt_thread_mutex_destroy(&process->cp_mutex);
1400
1350 if (process->init != NULL) {
1351 nxt_mp_destroy(process->init->mem_pool);
1401 /* processes from nxt_runtime_process_get() have no memory pool */
1402 if (process->mem_pool != NULL) {
1403 nxt_mp_destroy(process->mem_pool);
1352 }
1353
1354 nxt_mp_free(rt->mem_pool, process);
1355}
1356
1357
1358static nxt_int_t
1359nxt_runtime_lvlhsh_pid_test(nxt_lvlhsh_query_t *lhq, void *data)

--- 289 unchanged lines hidden ---
1404 }
1405
1406 nxt_mp_free(rt->mem_pool, process);
1407}
1408
1409
1410static nxt_int_t
1411nxt_runtime_lvlhsh_pid_test(nxt_lvlhsh_query_t *lhq, void *data)

--- 289 unchanged lines hidden ---