From bcc799a16ebb171b9be60a9ac69312ef020e7358 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Apr 2025 16:49:34 +0800 Subject: [PATCH] unix: use pipe_fname if getsockname returns nothing (#4748) On some platforms (like GNU/Hurd), `getsockname` returns an empty string for sockets in the UNIX domain. However, we do have stored the path info in `pipe_fname` of `uv_pipe_t`, so we can try with it if `getsockname` returns an empty string. --- src/unix/pipe.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/unix/pipe.c b/src/unix/pipe.c index 680e0664b..68e225e2e 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -450,6 +450,7 @@ int uv_pipe_chmod(uv_pipe_t* handle, int mode) { char name_buffer[1 + UV__PATH_MAX]; int desired_mode; size_t name_len; + const char* name; int fd; int r; @@ -481,8 +482,13 @@ int uv_pipe_chmod(uv_pipe_t* handle, int mode) { r = uv_pipe_getsockname(handle, name_buffer, &name_len); if (r != 0) return r; + name = name_buffer; - if (chmod(name_buffer, desired_mode)) + /* On some platforms, getsockname returns an empty string, and we try with pipe_fname. */ + if (name_len == 0 && handle->pipe_fname != NULL) + name = handle->pipe_fname; + + if (chmod(name, desired_mode)) return UV__ERR(errno); return 0;