Deleted
Added
nxt_controller.c (1787:db82aa07015c) | nxt_controller.c (1926:6e85d6c0b8bb) |
---|---|
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> --- 78 unchanged lines hidden (view full) --- 87static void nxt_controller_process_cert(nxt_task_t *task, 88 nxt_controller_request_t *req, nxt_str_t *path); 89static void nxt_controller_process_cert_save(nxt_task_t *task, 90 nxt_port_recv_msg_t *msg, void *data); 91static nxt_bool_t nxt_controller_cert_in_use(nxt_str_t *name); 92static void nxt_controller_cert_cleanup(nxt_task_t *task, void *obj, 93 void *data); 94#endif | 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> --- 78 unchanged lines hidden (view full) --- 87static void nxt_controller_process_cert(nxt_task_t *task, 88 nxt_controller_request_t *req, nxt_str_t *path); 89static void nxt_controller_process_cert_save(nxt_task_t *task, 90 nxt_port_recv_msg_t *msg, void *data); 91static nxt_bool_t nxt_controller_cert_in_use(nxt_str_t *name); 92static void nxt_controller_cert_cleanup(nxt_task_t *task, void *obj, 93 void *data); 94#endif |
95static void nxt_controller_process_control(nxt_task_t *task, 96 nxt_controller_request_t *req, nxt_str_t *path); 97static void nxt_controller_app_restart_handler(nxt_task_t *task, 98 nxt_port_recv_msg_t *msg, void *data); |
|
95static void nxt_controller_conf_handler(nxt_task_t *task, 96 nxt_port_recv_msg_t *msg, void *data); 97static void nxt_controller_conf_store(nxt_task_t *task, 98 nxt_conf_value_t *conf); 99static void nxt_controller_response(nxt_task_t *task, 100 nxt_controller_request_t *req, nxt_controller_response_t *resp); 101static u_char *nxt_controller_date(u_char *buf, nxt_realtime_t *now, 102 struct tm *tm, size_t size, const char *format); --- 914 unchanged lines hidden (view full) --- 1017 } 1018 1019 nxt_controller_process_cert(task, req, &path); 1020 return; 1021 } 1022 1023#endif 1024 | 99static void nxt_controller_conf_handler(nxt_task_t *task, 100 nxt_port_recv_msg_t *msg, void *data); 101static void nxt_controller_conf_store(nxt_task_t *task, 102 nxt_conf_value_t *conf); 103static void nxt_controller_response(nxt_task_t *task, 104 nxt_controller_request_t *req, nxt_controller_response_t *resp); 105static u_char *nxt_controller_date(u_char *buf, nxt_realtime_t *now, 106 struct tm *tm, size_t size, const char *format); --- 914 unchanged lines hidden (view full) --- 1021 } 1022 1023 nxt_controller_process_cert(task, req, &path); 1024 return; 1025 } 1026 1027#endif 1028 |
1029 if (nxt_str_start(&path, "/control/", 9)) { 1030 path.length -= 9; 1031 path.start += 9; 1032 1033 nxt_controller_process_control(task, req, &path); 1034 return; 1035 } 1036 |
|
1025 nxt_memzero(&resp, sizeof(nxt_controller_response_t)); 1026 1027 if (path.length == 1 && path.start[0] == '/') { 1028 1029 if (!nxt_str_eq(&req->parser.method, "GET", 3)) { 1030 goto invalid_method; 1031 } 1032 --- 646 unchanged lines hidden (view full) --- 1679 1680 nxt_controller_response(task, req, &resp); 1681 1682 nxt_controller_flush_requests(task); 1683} 1684 1685 1686static void | 1037 nxt_memzero(&resp, sizeof(nxt_controller_response_t)); 1038 1039 if (path.length == 1 && path.start[0] == '/') { 1040 1041 if (!nxt_str_eq(&req->parser.method, "GET", 3)) { 1042 goto invalid_method; 1043 } 1044 --- 646 unchanged lines hidden (view full) --- 1691 1692 nxt_controller_response(task, req, &resp); 1693 1694 nxt_controller_flush_requests(task); 1695} 1696 1697 1698static void |
1699nxt_controller_process_control(nxt_task_t *task, 1700 nxt_controller_request_t *req, nxt_str_t *path) 1701{ 1702 uint32_t stream; 1703 nxt_buf_t *b; 1704 nxt_int_t rc; 1705 nxt_port_t *router_port, *controller_port; 1706 nxt_runtime_t *rt; 1707 nxt_conf_value_t *value; 1708 nxt_controller_response_t resp; 1709 1710 static nxt_str_t applications = nxt_string("applications"); 1711 1712 nxt_memzero(&resp, sizeof(nxt_controller_response_t)); 1713 1714 if (!nxt_str_eq(&req->parser.method, "GET", 3)) { 1715 goto not_allowed; 1716 } 1717 1718 if (!nxt_str_start(path, "applications/", 13) 1719 || nxt_memcmp(path->start + path->length - 8, "/restart", 8) != 0) 1720 { 1721 goto not_found; 1722 } 1723 1724 path->start += 13; 1725 path->length -= 13 + 8; 1726 1727 if (nxt_controller_check_postpone_request(task)) { 1728 nxt_queue_insert_tail(&nxt_controller_waiting_requests, &req->link); 1729 return; 1730 } 1731 1732 value = nxt_controller_conf.root; 1733 if (value == NULL) { 1734 goto not_found; 1735 } 1736 1737 value = nxt_conf_get_object_member(value, &applications, NULL); 1738 if (value == NULL) { 1739 goto not_found; 1740 } 1741 1742 value = nxt_conf_get_object_member(value, path, NULL); 1743 if (value == NULL) { 1744 goto not_found; 1745 } 1746 1747 b = nxt_buf_mem_alloc(req->conn->mem_pool, path->length, 0); 1748 if (nxt_slow_path(b == NULL)) { 1749 goto alloc_fail; 1750 } 1751 1752 b->mem.free = nxt_cpymem(b->mem.pos, path->start, path->length); 1753 1754 rt = task->thread->runtime; 1755 1756 controller_port = rt->port_by_type[NXT_PROCESS_CONTROLLER]; 1757 router_port = rt->port_by_type[NXT_PROCESS_ROUTER]; 1758 1759 stream = nxt_port_rpc_register_handler(task, controller_port, 1760 nxt_controller_app_restart_handler, 1761 nxt_controller_app_restart_handler, 1762 router_port->pid, req); 1763 if (nxt_slow_path(stream == 0)) { 1764 goto alloc_fail; 1765 } 1766 1767 rc = nxt_port_socket_write(task, router_port, NXT_PORT_MSG_APP_RESTART, 1768 -1, stream, 0, b); 1769 if (nxt_slow_path(rc != NXT_OK)) { 1770 nxt_port_rpc_cancel(task, controller_port, stream); 1771 1772 goto fail; 1773 } 1774 1775 nxt_queue_insert_head(&nxt_controller_waiting_requests, &req->link); 1776 1777 return; 1778 1779not_allowed: 1780 1781 resp.status = 405; 1782 resp.title = (u_char *) "Method isn't allowed."; 1783 resp.offset = -1; 1784 1785 nxt_controller_response(task, req, &resp); 1786 return; 1787 1788not_found: 1789 1790 resp.status = 404; 1791 resp.title = (u_char *) "Value doesn't exist."; 1792 resp.offset = -1; 1793 1794 nxt_controller_response(task, req, &resp); 1795 return; 1796 1797alloc_fail: 1798 1799 resp.status = 500; 1800 resp.title = (u_char *) "Memory allocation failed."; 1801 resp.offset = -1; 1802 1803 nxt_controller_response(task, req, &resp); 1804 return; 1805 1806fail: 1807 1808 resp.status = 500; 1809 resp.title = (u_char *) "Send restart failed."; 1810 resp.offset = -1; 1811 1812 nxt_controller_response(task, req, &resp); 1813} 1814 1815 1816static void 1817nxt_controller_app_restart_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg, 1818 void *data) 1819{ 1820 nxt_controller_request_t *req; 1821 nxt_controller_response_t resp; 1822 1823 req = data; 1824 1825 nxt_debug(task, "controller app restart handler"); 1826 1827 nxt_queue_remove(&req->link); 1828 1829 nxt_memzero(&resp, sizeof(nxt_controller_response_t)); 1830 1831 if (msg->port_msg.type == NXT_PORT_MSG_RPC_READY) { 1832 resp.status = 200; 1833 resp.title = (u_char *) "Ok"; 1834 1835 } else { 1836 resp.status = 500; 1837 resp.title = (u_char *) "Failed to restart app."; 1838 resp.offset = -1; 1839 } 1840 1841 nxt_controller_response(task, req, &resp); 1842 1843 nxt_controller_flush_requests(task); 1844} 1845 1846 1847static void |
|
1687nxt_controller_conf_store(nxt_task_t *task, nxt_conf_value_t *conf) 1688{ 1689 void *mem; 1690 u_char *end; 1691 size_t size; 1692 nxt_fd_t fd; 1693 nxt_buf_t *b; 1694 nxt_port_t *main_port; --- 232 unchanged lines hidden --- | 1848nxt_controller_conf_store(nxt_task_t *task, nxt_conf_value_t *conf) 1849{ 1850 void *mem; 1851 u_char *end; 1852 size_t size; 1853 nxt_fd_t fd; 1854 nxt_buf_t *b; 1855 nxt_port_t *main_port; --- 232 unchanged lines hidden --- |