summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Cobbley <david.j.cobbley@linux.intel.com>2017-11-13 16:19:09 -0800
committerDavid Cobbley <david.j.cobbley@linux.intel.com>2017-11-16 07:57:34 -0800
commit2c15f0c3dfd3cb5ecece1156ba9372b987f53acd (patch)
treef505b6826326948b9536e8729db11b10691a1522
parentbd45aae1db0643570ebad03f8d2a39e5cac53c8d (diff)
downloadphosphor-net-ipmid-2c15f0c3dfd3cb5ecece1156ba9372b987f53acd.tar.gz
phosphor-net-ipmid-2c15f0c3dfd3cb5ecece1156ba9372b987f53acd.zip
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 <david.j.cobbley@linux.intel.com>
-rw-r--r--sd_event_loop.cpp34
1 files changed, 31 insertions, 3 deletions
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 <netinet/in.h>
#include <sys/ioctl.h>
+#include <sys/socket.h>
#include <systemd/sd-daemon.h>
#include <phosphor-logging/log.hpp>
#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<level::ERR>("No or too many file descriptors received");
+ fd = SD_LISTEN_FDS_START;
+ }
+ else if (listen_fd > 1)
+ {
+ log<level::ERR>("Too many file descriptors received");
goto finish;
}
+ else
+ {
+ struct sockaddr_in address;
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == 0)
+ {
+ r = -errno;
+ log<level::ERR>("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<level::ERR>("Unable to bind socket");
+ goto finish;
+ }
+ }
r = sd_event_add_io(event, &source, fd, EPOLLIN, udp623Handler, nullptr);
if (r < 0)
OpenPOWER on IntegriCloud