[PATCH v4 RESEND 4/5] Log abstract Unix domain sockets with a leading '@'.

Alejandro Colomar alx.manpages at gmail.com
Tue Aug 23 23:02:37 UTC 2022


Translate the leading NUL (aka ^@, '\0') of abstract Unix sockets
into @ for user visible strings, since @ is readable by all tools.

Co-developed-by: Andrew Clayton <a.clayton at f5.com>
Signed-off-by: Andrew Clayton <a.clayton at f5.com>
Signed-off-by: Alejandro Colomar <alx.manpages at gmail.com>
Cc: Bjornar Ness <bjornar.ness at gmail.com>
---
 src/core/ngx_inet.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
index 4a455e5b..bf1799d4 100644
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -244,6 +244,11 @@ ngx_sock_ntop(struct sockaddr *sa, socklen_t socklen, u_char *text, size_t len,
         if (socklen <= (socklen_t) offsetof(struct sockaddr_un, sun_path)) {
             p = ngx_snprintf(text, len, "unix:%Z");
 
+        } else if (saun->sun_path[0] == '\0') {
+            n = strnlen(&saun->sun_path[1],
+                        socklen - offsetof(struct sockaddr_un, sun_path) - 1);
+            p = ngx_snprintf(text, len, "unix:@%*s%Z", n, &saun->sun_path[1]);
+
         } else {
             n = ngx_strnlen((u_char *) saun->sun_path,
                             socklen - offsetof(struct sockaddr_un, sun_path));
-- 
2.37.2



More information about the nginx-devel mailing list