[nginx] Add abstract socket support on Linux
Bjørnar Ness
bjornar.ness at gmail.com
Mon Mar 11 13:49:33 UTC 2019
# HG changeset patch
# User Bjornar Ness <bjornar.ness at gmail.com>
# Date 1552311828 -3600
# Mon Mar 11 14:43:48 2019 +0100
# Node ID 9bf37762c5066b2f0ec3e6a312d97c86c4fdba18
# Parent c74904a1702135f673a275bd0d36f010a3bfb89a
Add abstract socket support on Linux
This patch adds abstract socket support for Linux, making it possible
to both listen and connect to abstract socket:
server {
listen unix:@abstract-socket;
}
This is convenient for ephemeral sockets for i.e fastcgi/uwsgi
diff -r c74904a17021 -r 9bf37762c506 src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Sat Mar 09 03:03:56 2019 +0300
+++ b/src/core/ngx_connection.c Mon Mar 11 14:43:48 2019 +0100
@@ -625,7 +625,12 @@
#if (NGX_HAVE_UNIX_DOMAIN)
- if (ls[i].sockaddr->sa_family == AF_UNIX) {
+ if (ls[i].sockaddr->sa_family == AF_UNIX
+#if (NGX_LINUX)
+ && ls[i].addr_text.data[sizeof("unix:") - 1] != '@'
+#endif
+ )
+ {
mode_t mode;
u_char *name;
@@ -1069,6 +1074,9 @@
#if (NGX_HAVE_UNIX_DOMAIN)
if (ls[i].sockaddr->sa_family == AF_UNIX
+#if (NGX_LINUX)
+ && ls[i].addr_text.data[sizeof("unix:") - 1] != '@'
+#endif
&& ngx_process <= NGX_PROCESS_MASTER
&& ngx_new_binary == 0)
{
diff -r c74904a17021 -r 9bf37762c506 src/core/ngx_cycle.c
--- a/src/core/ngx_cycle.c Sat Mar 09 03:03:56 2019 +0300
+++ b/src/core/ngx_cycle.c Mon Mar 11 14:43:48 2019 +0100
@@ -709,7 +709,12 @@
#if (NGX_HAVE_UNIX_DOMAIN)
- if (ls[i].sockaddr->sa_family == AF_UNIX) {
+ if (ls[i].sockaddr->sa_family == AF_UNIX
+#if (NGX_LINUX)
+ && ls[i].addr_text.data[sizeof("unix:") - 1] != '@'
+#endif
+ )
+ {
u_char *name;
name = ls[i].addr_text.data + sizeof("unix:") - 1;
diff -r c74904a17021 -r 9bf37762c506 src/core/ngx_inet.c
--- a/src/core/ngx_inet.c Sat Mar 09 03:03:56 2019 +0300
+++ b/src/core/ngx_inet.c Mon Mar 11 14:43:48 2019 +0100
@@ -242,6 +242,9 @@
if (socklen <= (socklen_t) offsetof(struct sockaddr_un, sun_path)) {
p = ngx_snprintf(text, len, "unix:%Z");
+ } else if (saun->sun_path[0] == '\0') {
+ p = ngx_snprintf(text, len, "unix:@%s%Z", &saun->sun_path[1]);
+
} else {
n = ngx_strnlen((u_char *) saun->sun_path,
socklen - offsetof(struct sockaddr_un, sun_path));
@@ -744,6 +747,13 @@
saun->sun_family = AF_UNIX;
(void) ngx_cpystrn((u_char *) saun->sun_path, path, len);
+#if (NGX_LINUX)
+ if (path[0] == '@') {
+ saun->sun_path[0] = '\0';
+ u->socklen = sizeof(sa_family_t) + strlen(path);
+ }
+#endif
+
u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));
if (u->addrs == NULL) {
return NGX_ERROR;
@@ -765,6 +775,13 @@
u->addrs[0].name.len = len + 4;
u->addrs[0].name.data = u->url.data;
+#if (NGX_LINUX)
+ if (path[0] == '@') {
+ saun->sun_path[0] = '\0';
+ u->addrs[0].socklen = sizeof(sa_family_t) + strlen(path);
+ }
+#endif
+
return NGX_OK;
#else
More information about the nginx-devel
mailing list