blob: d26193bd8894e46581cc71f18f1200e8b87a36b2 [file] [log] [blame]
Tom Joseph22c5ad32017-03-14 18:04:22 +05301#include <sys/socket.h>
2#include <sys/un.h>
3#include <cmath>
4#include <phosphor-logging/log.hpp>
5#include "main.hpp"
6#include "sol_context.hpp"
7#include "sol_manager.hpp"
8
9namespace sol
10{
11
12using namespace phosphor::logging;
13
14void Manager::initHostConsoleFd()
15{
16 struct sockaddr_un addr;
17 int rc = 0;
18 int fd = 0;
19
20 fd = socket(AF_UNIX, SOCK_STREAM, 0);
21 if (fd < 0)
22 {
23 log<level::ERR>("Failed to open the host console socket",
24 entry("ERRNO=%d", errno));
25 throw std::runtime_error("Failed to open the host console socket");
26 }
27
28 memset(&addr, 0, sizeof(addr));
29 addr.sun_family = AF_UNIX;
30 memcpy(&addr.sun_path, &CONSOLE_SOCKET_PATH, CONSOLE_SOCKET_PATH_LEN);
31 consoleFD = std::make_unique<CustomFD>(fd);
32 auto& conFD = *(consoleFD.get());
33
34 rc = connect(conFD(), (struct sockaddr *)&addr, sizeof(addr));
35 if (rc < 0)
36 {
37 log<level::ERR>("Failed to connect to host console socket address",
38 entry("ERRNO=%d", errno));
39 consoleFD.reset();
40 throw std::runtime_error("Failed to connect to console server");
41 }
42}
43
44} // namespace sol