summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/nxt_main_process.c46
-rw-r--r--src/nxt_port.h3
-rw-r--r--src/nxt_router.c41
3 files changed, 87 insertions, 3 deletions
diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c
index 7548be9a..db1cfcb9 100644
--- a/src/nxt_main_process.c
+++ b/src/nxt_main_process.c
@@ -48,6 +48,8 @@ static void nxt_main_process_signal_handler(nxt_task_t *task, void *obj,
static void nxt_main_process_cleanup(nxt_task_t *task, nxt_process_t *process);
static void nxt_main_port_socket_handler(nxt_task_t *task,
nxt_port_recv_msg_t *msg);
+static void nxt_main_port_socket_unlink_handler(nxt_task_t *task,
+ nxt_port_recv_msg_t *msg);
static nxt_int_t nxt_main_listening_socket(nxt_sockaddr_t *sa,
nxt_listening_socket_t *ls);
static void nxt_main_port_modules_handler(nxt_task_t *task,
@@ -587,6 +589,7 @@ static nxt_port_handlers_t nxt_main_process_port_handlers = {
.remove_pid = nxt_port_remove_pid_handler,
.start_process = nxt_main_start_process_handler,
.socket = nxt_main_port_socket_handler,
+ .socket_unlink = nxt_main_port_socket_unlink_handler,
.modules = nxt_main_port_modules_handler,
.conf_store = nxt_main_port_conf_store_handler,
#if (NXT_TLS)
@@ -1214,6 +1217,49 @@ fail:
}
+static void
+nxt_main_port_socket_unlink_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
+{
+#if (NXT_HAVE_UNIX_DOMAIN)
+ size_t i;
+ nxt_buf_t *b;
+ const char *filename;
+ nxt_runtime_t *rt;
+ nxt_sockaddr_t *sa;
+ nxt_listen_socket_t *ls;
+
+ b = msg->buf;
+ sa = (nxt_sockaddr_t *) b->mem.pos;
+
+ filename = sa->u.sockaddr_un.sun_path;
+ unlink(filename);
+
+ rt = task->thread->runtime;
+
+ for (i = 0; i < rt->listen_sockets->nelts; i++) {
+ const char *name;
+
+ ls = (nxt_listen_socket_t *) rt->listen_sockets->elts + i;
+ sa = ls->sockaddr;
+
+ if (sa->u.sockaddr.sa_family != AF_UNIX
+ || sa->u.sockaddr_un.sun_path[0] == '\0')
+ {
+ continue;
+ }
+
+ name = sa->u.sockaddr_un.sun_path;
+ if (strcmp(name, filename) != 0) {
+ continue;
+ }
+
+ nxt_array_remove(rt->listen_sockets, ls);
+ break;
+ }
+#endif
+}
+
+
static nxt_conf_map_t nxt_app_lang_module_map[] = {
{
nxt_string("type"),
diff --git a/src/nxt_port.h b/src/nxt_port.h
index 3a8da5ad..eba8d06f 100644
--- a/src/nxt_port.h
+++ b/src/nxt_port.h
@@ -16,6 +16,7 @@ struct nxt_port_handlers_s {
/* Main process RPC requests. */
nxt_port_handler_t start_process;
nxt_port_handler_t socket;
+ nxt_port_handler_t socket_unlink;
nxt_port_handler_t modules;
nxt_port_handler_t conf_store;
nxt_port_handler_t cert_get;
@@ -81,6 +82,7 @@ typedef enum {
_NXT_PORT_MSG_START_PROCESS = nxt_port_handler_idx(start_process),
_NXT_PORT_MSG_SOCKET = nxt_port_handler_idx(socket),
+ _NXT_PORT_MSG_SOCKET_UNLINK = nxt_port_handler_idx(socket_unlink),
_NXT_PORT_MSG_MODULES = nxt_port_handler_idx(modules),
_NXT_PORT_MSG_CONF_STORE = nxt_port_handler_idx(conf_store),
_NXT_PORT_MSG_CERT_GET = nxt_port_handler_idx(cert_get),
@@ -122,6 +124,7 @@ typedef enum {
NXT_PORT_MSG_RPC_ERROR = nxt_msg_last(_NXT_PORT_MSG_RPC_ERROR),
NXT_PORT_MSG_START_PROCESS = nxt_msg_last(_NXT_PORT_MSG_START_PROCESS),
NXT_PORT_MSG_SOCKET = nxt_msg_last(_NXT_PORT_MSG_SOCKET),
+ NXT_PORT_MSG_SOCKET_UNLINK = nxt_msg_last(_NXT_PORT_MSG_SOCKET_UNLINK),
NXT_PORT_MSG_MODULES = nxt_msg_last(_NXT_PORT_MSG_MODULES),
NXT_PORT_MSG_CONF_STORE = nxt_msg_last(_NXT_PORT_MSG_CONF_STORE),
NXT_PORT_MSG_CERT_GET = nxt_msg_last(_NXT_PORT_MSG_CERT_GET),
diff --git a/src/nxt_router.c b/src/nxt_router.c
index 17fe0418..baede83b 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -3686,6 +3686,13 @@ nxt_router_listen_socket_close(nxt_task_t *task, void *obj, void *data)
static void
nxt_router_listen_socket_release(nxt_task_t *task, nxt_socket_conf_t *skcf)
{
+#if (NXT_HAVE_UNIX_DOMAIN)
+ size_t size;
+ nxt_buf_t *b;
+ nxt_port_t *main_port;
+ nxt_runtime_t *rt;
+ nxt_sockaddr_t *sa;
+#endif
nxt_listen_socket_t *ls;
nxt_thread_spinlock_t *lock;
@@ -3703,10 +3710,38 @@ nxt_router_listen_socket_release(nxt_task_t *task, nxt_socket_conf_t *skcf)
nxt_thread_spin_unlock(lock);
- if (ls != NULL) {
- nxt_socket_close(task, ls->socket);
- nxt_free(ls);
+ if (ls == NULL) {
+ return;
+ }
+
+ nxt_socket_close(task, ls->socket);
+
+#if (NXT_HAVE_UNIX_DOMAIN)
+ sa = ls->sockaddr;
+ if (sa->u.sockaddr.sa_family != AF_UNIX
+ || sa->u.sockaddr_un.sun_path[0] == '\0')
+ {
+ goto out_free_ls;
}
+
+ size = nxt_sockaddr_size(ls->sockaddr);
+
+ b = nxt_buf_mem_alloc(task->thread->engine->mem_pool, size, 0);
+ if (b == NULL) {
+ goto out_free_ls;
+ }
+
+ b->mem.free = nxt_cpymem(b->mem.free, ls->sockaddr, size);
+
+ rt = task->thread->runtime;
+ main_port = rt->port_by_type[NXT_PROCESS_MAIN];
+
+ (void) nxt_port_socket_write(task, main_port, NXT_PORT_MSG_SOCKET_UNLINK,
+ -1, 0, 0, b);
+
+out_free_ls:
+#endif
+ nxt_free(ls);
}