From a7009a03539b1d56d77c29c68da73b26c71a4ce1 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Thu, 3 Mar 2016 14:56:04 -0500 Subject: [PATCH] unix: fix uv__handle_type for AIX 'getsockname' does not handle UNIX domain sockets on AIX[1], it does not fail but simply returns an empty structure with length 0. If 'getsockname' does not fail (i.e. does not return -1) and the length is 0 we know, on AIX, that the type is AF_UNIX. This fixes test pipe_sendmsg. [1] https://goo.gl/ozqcmS PR-URL: https://github.com/libuv/libuv/pull/748 Reviewed-By: Ben Noordhuis --- src/unix/stream.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/unix/stream.c b/src/unix/stream.c index 4da6ce67..9043664d 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -946,13 +946,14 @@ static void uv__write_callbacks(uv_stream_t* stream) { uv_handle_type uv__handle_type(int fd) { struct sockaddr_storage ss; + socklen_t sslen; socklen_t len; int type; memset(&ss, 0, sizeof(ss)); - len = sizeof(ss); + sslen = sizeof(ss); - if (getsockname(fd, (struct sockaddr*)&ss, &len)) + if (getsockname(fd, (struct sockaddr*)&ss, &sslen)) return UV_UNKNOWN_HANDLE; len = sizeof type; @@ -961,6 +962,14 @@ uv_handle_type uv__handle_type(int fd) { return UV_UNKNOWN_HANDLE; if (type == SOCK_STREAM) { +#if defined(_AIX) + /* on AIX the getsockname call returns an empty sa structure + * for sockets of type AF_UNIX. For all other types it will + * return a properly filled in structure. + */ + if (sslen == 0) + return UV_NAMED_PIPE; +#endif switch (ss.ss_family) { case AF_UNIX: return UV_NAMED_PIPE;