obmc-console-server: bind/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: I6560ba8b2a25a60644873adf66f02a60ded42b1d
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/console-client.c b/console-client.c
index 63c4e70..1b53624 100644
--- a/console-client.c
+++ b/console-client.c
@@ -173,7 +173,7 @@
memcpy(&addr.sun_path, &console_socket_path, console_socket_path_len);
rc = connect(client->console_sd, (struct sockaddr *)&addr,
- sizeof(addr));
+ sizeof(addr) - sizeof(addr.sun_path) + console_socket_path_len);
if (rc) {
warn("Can't connect to console server");
close(client->console_sd);