phosphor-hostlogger: connect with the correct sockaddr size
Abstract unix sockets start with the nul-charater, but are not nul
terminated. In fact, the nul-character has no meaning in the path.
According to the man page unix(7),
abstract: an abstract socket address is distinguished (from a pathname
socket) by the fact that sun_path[0] is a null byte ('\0').
The socket's address in this namespace is given by the
additional bytes in sun_path that are covered by the
specified length of the address structure. (Null bytes in
the name have no special significance.)
This means that when calling bind/connect, the size of the sockaddr
structure is not sizeof(sockaddr_un), it is sizeof(sockaddr_un) -
sizeof(sun_path) + (path_len)
Change-Id: I8e46d727c7ffc2fa1799274568c414fbbac306a7
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/src/log_manager.cpp b/src/log_manager.cpp
index 506e586..66a08c6 100644
--- a/src/log_manager.cpp
+++ b/src/log_manager.cpp
@@ -98,7 +98,8 @@
++attempt)
{
rc = connect(fd_, reinterpret_cast<const sockaddr*>(&sa),
- sizeof(sa));
+ sizeof(sa) - sizeof(sa.sun_path) +
+ sizeof(HOSTLOG_SOCKET_PATH) - 1);
sleep(HOSTLOG_SOCKET_PAUSE);
}
if (rc < 0)