Change socket path appending
This commit changes socketPath back to "\0obmc-console" and will append
configured socket ID to it if exists or append "default" as the default
socket ID. This help SOCKET_ID configured in configuration files can be
compatible with obmc-console.
Change-Id: I8539740030b3f9f28a049a4f6c721dd0419ec32f
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
diff --git a/src/host_console.cpp b/src/host_console.cpp
index b4fe511..3eb5d30 100644
--- a/src/host_console.cpp
+++ b/src/host_console.cpp
@@ -15,7 +15,8 @@
* @brief Base path to the console's socket.
* See obmc-console for details.
*/
-static constexpr char socketPath[] = "\0obmc-console.default";
+static constexpr char socketPath[] = "\0obmc-console";
+static constexpr std::string defaultSocketId = "default";
HostConsole::HostConsole(const std::string& socketId) :
socketId(socketId), socketFd(-1)
@@ -54,11 +55,15 @@
// Construct path to the socket file (see obmc-console for details)
std::string path(socketPath, socketPath + sizeof(socketPath) - 1);
+ path += '.';
if (!socketId.empty())
{
- path += '.';
path += socketId;
}
+ else
+ {
+ path += defaultSocketId;
+ }
if (path.length() > sizeof(sockaddr_un::sun_path))
{
throw std::invalid_argument("Invalid socket ID");
diff --git a/test/host_console_test.cpp b/test/host_console_test.cpp
index 6334e24..6a16148 100644
--- a/test/host_console_test.cpp
+++ b/test/host_console_test.cpp
@@ -8,7 +8,8 @@
#include <gtest/gtest.h>
-static constexpr char socketPath[] = "\0obmc-console.default";
+static constexpr char socketPath[] = "\0obmc-console";
+static constexpr std::string defaultSocketId = "default";
/**
* @class HostConsoleTest
@@ -23,11 +24,15 @@
serverSocket = socket(AF_UNIX, SOCK_STREAM, 0);
ASSERT_NE(serverSocket, -1);
std::string path(socketPath, socketPath + sizeof(socketPath) - 1);
+ path += '.';
if (*socketId)
{
- path += '.';
path += socketId;
}
+ else
+ {
+ path += defaultSocketId;
+ }
sockaddr_un sa;
sa.sun_family = AF_UNIX;
memcpy(&sa.sun_path, path.c_str(), path.length());