nxt_main_process.c (1927:ac8d11e34427) nxt_main_process.c (1969:be6409cdb028)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8#include <nxt_runtime.h>

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

58 nxt_port_recv_msg_t *msg);
59static nxt_int_t nxt_main_listening_socket(nxt_sockaddr_t *sa,
60 nxt_listening_socket_t *ls);
61static void nxt_main_port_modules_handler(nxt_task_t *task,
62 nxt_port_recv_msg_t *msg);
63static int nxt_cdecl nxt_app_lang_compare(const void *v1, const void *v2);
64static void nxt_main_port_conf_store_handler(nxt_task_t *task,
65 nxt_port_recv_msg_t *msg);
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8#include <nxt_runtime.h>

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

58 nxt_port_recv_msg_t *msg);
59static nxt_int_t nxt_main_listening_socket(nxt_sockaddr_t *sa,
60 nxt_listening_socket_t *ls);
61static void nxt_main_port_modules_handler(nxt_task_t *task,
62 nxt_port_recv_msg_t *msg);
63static int nxt_cdecl nxt_app_lang_compare(const void *v1, const void *v2);
64static void nxt_main_port_conf_store_handler(nxt_task_t *task,
65 nxt_port_recv_msg_t *msg);
66static nxt_int_t nxt_main_file_store(nxt_task_t *task, const char *tmp_name,
67 const char *name, u_char *buf, size_t size);
66static void nxt_main_port_access_log_handler(nxt_task_t *task,
67 nxt_port_recv_msg_t *msg);
68
69const nxt_sig_event_t nxt_main_process_signals[] = {
70 nxt_event_signal(SIGHUP, nxt_main_process_signal_handler),
71 nxt_event_signal(SIGINT, nxt_main_process_sigterm_handler),
72 nxt_event_signal(SIGQUIT, nxt_main_process_sigquit_handler),
73 nxt_event_signal(SIGTERM, nxt_main_process_sigterm_handler),
74 nxt_event_signal(SIGCHLD, nxt_main_process_sigchld_handler),
75 nxt_event_signal(SIGUSR1, nxt_main_process_sigusr1_handler),
76 nxt_event_signal_end,
77};
78
79
68static void nxt_main_port_access_log_handler(nxt_task_t *task,
69 nxt_port_recv_msg_t *msg);
70
71const nxt_sig_event_t nxt_main_process_signals[] = {
72 nxt_event_signal(SIGHUP, nxt_main_process_signal_handler),
73 nxt_event_signal(SIGINT, nxt_main_process_sigterm_handler),
74 nxt_event_signal(SIGQUIT, nxt_main_process_sigquit_handler),
75 nxt_event_signal(SIGTERM, nxt_main_process_sigterm_handler),
76 nxt_event_signal(SIGCHLD, nxt_main_process_sigchld_handler),
77 nxt_event_signal(SIGUSR1, nxt_main_process_sigusr1_handler),
78 nxt_event_signal_end,
79};
80
81
82nxt_uint_t nxt_conf_ver;
83
80static nxt_bool_t nxt_exiting;
81
82
83nxt_int_t
84nxt_main_process_start(nxt_thread_t *thr, nxt_task_t *task,
85 nxt_runtime_t *rt)
86{
87 rt->type = NXT_PROCESS_MAIN;

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

1414 return -n;
1415}
1416
1417
1418static void
1419nxt_main_port_conf_store_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
1420{
1421 void *p;
84static nxt_bool_t nxt_exiting;
85
86
87nxt_int_t
88nxt_main_process_start(nxt_thread_t *thr, nxt_task_t *task,
89 nxt_runtime_t *rt)
90{
91 rt->type = NXT_PROCESS_MAIN;

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

1418 return -n;
1419}
1420
1421
1422static void
1423nxt_main_port_conf_store_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
1424{
1425 void *p;
1422 size_t size;
1423 ssize_t n;
1426 size_t n, size;
1424 nxt_int_t ret;
1427 nxt_int_t ret;
1425 nxt_file_t file;
1426 nxt_runtime_t *rt;
1428 nxt_runtime_t *rt;
1429 u_char ver[NXT_INT_T_LEN];
1427
1428 p = MAP_FAILED;
1429
1430 /*
1431 * Ancient compilers like gcc 4.8.5 on CentOS 7 wants 'size' to be
1432 * initialized in 'cleanup' section.
1433 */
1434 size = 0;

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

1452 msg->fd[0] = -1;
1453
1454 if (nxt_slow_path(p == MAP_FAILED)) {
1455 goto error;
1456 }
1457
1458 nxt_debug(task, "conf_store_handler(%uz): %*s", size, size, p);
1459
1430
1431 p = MAP_FAILED;
1432
1433 /*
1434 * Ancient compilers like gcc 4.8.5 on CentOS 7 wants 'size' to be
1435 * initialized in 'cleanup' section.
1436 */
1437 size = 0;

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

1455 msg->fd[0] = -1;
1456
1457 if (nxt_slow_path(p == MAP_FAILED)) {
1458 goto error;
1459 }
1460
1461 nxt_debug(task, "conf_store_handler(%uz): %*s", size, size, p);
1462
1460 nxt_memzero(&file, sizeof(nxt_file_t));
1461
1462 rt = task->thread->runtime;
1463
1463 rt = task->thread->runtime;
1464
1464 file.name = (nxt_file_name_t *) rt->conf_tmp;
1465 if (nxt_conf_ver != NXT_VERNUM) {
1466 n = nxt_sprintf(ver, ver + NXT_INT_T_LEN, "%d", NXT_VERNUM) - ver;
1465
1467
1466 if (nxt_slow_path(nxt_file_open(task, &file, NXT_FILE_WRONLY,
1467 NXT_FILE_TRUNCATE, NXT_FILE_OWNER_ACCESS)
1468 != NXT_OK))
1469 {
1470 goto error;
1471 }
1468 ret = nxt_main_file_store(task, rt->ver_tmp, rt->ver, ver, n);
1469 if (nxt_slow_path(ret != NXT_OK)) {
1470 goto error;
1471 }
1472
1472
1473 n = nxt_file_write(&file, p, size, 0);
1474
1475 nxt_file_close(task, &file);
1476
1477 if (nxt_slow_path(n != (ssize_t) size)) {
1478 (void) nxt_file_delete(file.name);
1479 goto error;
1473 nxt_conf_ver = NXT_VERNUM;
1480 }
1481
1474 }
1475
1482 ret = nxt_file_rename(file.name, (nxt_file_name_t *) rt->conf);
1476 ret = nxt_main_file_store(task, rt->conf_tmp, rt->conf, p, size);
1483
1484 if (nxt_fast_path(ret == NXT_OK)) {
1485 goto cleanup;
1486 }
1487
1488error:
1489
1490 nxt_alert(task, "failed to store current configuration");

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

1497
1498 if (msg->fd[0] != -1) {
1499 nxt_fd_close(msg->fd[0]);
1500 msg->fd[0] = -1;
1501 }
1502}
1503
1504
1477
1478 if (nxt_fast_path(ret == NXT_OK)) {
1479 goto cleanup;
1480 }
1481
1482error:
1483
1484 nxt_alert(task, "failed to store current configuration");

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

1491
1492 if (msg->fd[0] != -1) {
1493 nxt_fd_close(msg->fd[0]);
1494 msg->fd[0] = -1;
1495 }
1496}
1497
1498
1499static nxt_int_t
1500nxt_main_file_store(nxt_task_t *task, const char *tmp_name, const char *name,
1501 u_char *buf, size_t size)
1502{
1503 ssize_t n;
1504 nxt_int_t ret;
1505 nxt_file_t file;
1506
1507 nxt_memzero(&file, sizeof(nxt_file_t));
1508
1509 file.name = (nxt_file_name_t *) name;
1510
1511 ret = nxt_file_open(task, &file, NXT_FILE_WRONLY, NXT_FILE_TRUNCATE,
1512 NXT_FILE_OWNER_ACCESS);
1513 if (nxt_slow_path(ret != NXT_OK)) {
1514 return NXT_ERROR;
1515 }
1516
1517 n = nxt_file_write(&file, buf, size, 0);
1518
1519 nxt_file_close(task, &file);
1520
1521 if (nxt_slow_path(n != (ssize_t) size)) {
1522 (void) nxt_file_delete(file.name);
1523 return NXT_ERROR;
1524 }
1525
1526 return nxt_file_rename(file.name, (nxt_file_name_t *) name);
1527}
1528
1529
1505static void
1506nxt_main_port_access_log_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
1507{
1508 u_char *path;
1509 nxt_int_t ret;
1510 nxt_file_t file;
1511 nxt_port_t *port;
1512 nxt_port_msg_type_t type;

--- 24 unchanged lines hidden ---
1530static void
1531nxt_main_port_access_log_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
1532{
1533 u_char *path;
1534 nxt_int_t ret;
1535 nxt_file_t file;
1536 nxt_port_t *port;
1537 nxt_port_msg_type_t type;

--- 24 unchanged lines hidden ---