From 2c15f0c3dfd3cb5ecece1156ba9372b987f53acd Mon Sep 17 00:00:00 2001 From: Dave Cobbley Date: Mon, 13 Nov 2017 16:19:09 -0800 Subject: Adding the capability to run netipmid outside of systemd Currently, this application relies upon systemd handing it a socket from the phosphor-ipmi-net.socket file. If for whatever reason, you want to run this application manually (perhaps debugging), it needs to create its own socket. This should have no affect on the normal operation of netipmid. Change-Id: I4e46b586b09cb57d5ef1d2fd0e216552da388381 Signed-off-by: David Cobbley --- sd_event_loop.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'sd_event_loop.cpp') diff --git a/sd_event_loop.cpp b/sd_event_loop.cpp index 0d8b323..16a5403 100644 --- a/sd_event_loop.cpp +++ b/sd_event_loop.cpp @@ -1,4 +1,6 @@ +#include #include +#include #include #include #include "main.hpp" @@ -173,6 +175,7 @@ int EventLoop::startEventLoop() { int fd = -1; int r = 0; + int listen_fd; sigset_t ss; sd_event_source* source = nullptr; auto bus = ipmid_get_sd_bus_connection(); @@ -218,13 +221,38 @@ int EventLoop::startEventLoop() goto finish; } - if (sd_listen_fds(0) != 1) + //Create our own socket if SysD did not supply one. + listen_fd = sd_listen_fds(0); + if (listen_fd == 1) { - log("No or too many file descriptors received"); + fd = SD_LISTEN_FDS_START; + } + else if (listen_fd > 1) + { + log("Too many file descriptors received"); goto finish; } + else + { + struct sockaddr_in address; + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == 0) + { + r = -errno; + log("Unable to manually open socket"); + goto finish; + } - fd = SD_LISTEN_FDS_START; + address.sin_family = AF_INET; + address.sin_addr.s_addr = INADDR_ANY; + address.sin_port = htons(IPMI_STD_PORT); + + if (bind(fd, (struct sockaddr *)&address, sizeof(address)) < 0) + { + r = -errno; + log("Unable to bind socket"); + goto finish; + } + } r = sd_event_add_io(event, &source, fd, EPOLLIN, udp623Handler, nullptr); if (r < 0) -- cgit v1.2.1