Commit be37f259 authored by Jonathan Currier's avatar Jonathan Currier

Migrate transport, and other mechanism away from poll, and to epoll.

This will easy the transition to making transports compile time
optional.

NOTE: this commit if unfinished and should eventually be rebased &
squashed.

specifically, the shutdown code no longer works correctly.
parent 200e3736
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
#include "backend.h" #include "backend.h"
#include "common.h" #include "common.h"
#include "dbus.h"
#include "lpc.h" #include "lpc.h"
#include "mboxd.h" #include "mboxd.h"
#include "protocol.h" #include "protocol.h"
#include "windows.h" #include "windows.h"
#include "hiomapd-state.h"
int control_ping(struct mbox_context *context) int control_ping(struct mbox_context *context)
{ {
......
...@@ -202,7 +202,7 @@ static int control_dbus_get_u8(sd_bus *bus, const char *path, ...@@ -202,7 +202,7 @@ static int control_dbus_get_u8(sd_bus *bus, const char *path,
sd_bus_message *reply, void *userdata, sd_bus_message *reply, void *userdata,
sd_bus_error *ret_error) sd_bus_error *ret_error)
{ {
struct mbox_context *context = userdata; struct mbox_context *context = dctx_to_mctx((struct transport_dbus_context*)userdata);
uint8_t value; uint8_t value;
assert(!strcmp(MBOX_DBUS_OBJECT, path)); assert(!strcmp(MBOX_DBUS_OBJECT, path));
...@@ -242,12 +242,12 @@ static const sd_bus_vtable mboxd_vtable[] = { ...@@ -242,12 +242,12 @@ static const sd_bus_vtable mboxd_vtable[] = {
SD_BUS_VTABLE_END SD_BUS_VTABLE_END
}; };
int control_dbus_init(struct mbox_context *context) int control_dbus_init(struct transport_dbus_context *dctx)
{ {
return sd_bus_add_object_vtable(context->bus, NULL, return sd_bus_add_object_vtable(dctx->bus, NULL,
MBOX_DBUS_OBJECT, MBOX_DBUS_OBJECT,
MBOX_DBUS_CONTROL_IFACE, MBOX_DBUS_CONTROL_IFACE,
mboxd_vtable, context); mboxd_vtable, dctx);
} }
#define __unused __attribute__((unused)) #define __unused __attribute__((unused))
......
...@@ -294,20 +294,19 @@ static const sd_bus_vtable control_legacy_vtable[] = { ...@@ -294,20 +294,19 @@ static const sd_bus_vtable control_legacy_vtable[] = {
SD_BUS_VTABLE_END SD_BUS_VTABLE_END
}; };
int control_legacy_init(struct mbox_context *context) int control_legacy_init(struct transport_dbus_context *dctx)
{ {
int rc; int rc;
rc = sd_bus_add_object_vtable(dctx->bus, NULL,
rc = sd_bus_add_object_vtable(context->bus, NULL,
MBOX_DBUS_LEGACY_OBJECT, MBOX_DBUS_LEGACY_OBJECT,
MBOX_DBUS_LEGACY_NAME, MBOX_DBUS_LEGACY_NAME,
control_legacy_vtable, context); control_legacy_vtable, dctx);
if (rc < 0) { if (rc < 0) {
MSG_ERR("Failed to register vtable: %s\n", strerror(-rc)); MSG_ERR("Failed to register vtable: %s\n", strerror(-rc));
return rc; return rc;
} }
return sd_bus_request_name(context->bus, MBOX_DBUS_LEGACY_NAME, return sd_bus_request_name(dctx->bus, MBOX_DBUS_LEGACY_NAME,
SD_BUS_NAME_ALLOW_REPLACEMENT | SD_BUS_NAME_ALLOW_REPLACEMENT |
SD_BUS_NAME_REPLACE_EXISTING); SD_BUS_NAME_REPLACE_EXISTING);
} }
......
...@@ -25,22 +25,24 @@ ...@@ -25,22 +25,24 @@
#define MBOX_DBUS_LEGACY_NAME "org.openbmc.mboxd" #define MBOX_DBUS_LEGACY_NAME "org.openbmc.mboxd"
#define MBOX_DBUS_LEGACY_OBJECT "/org/openbmc/mboxd" #define MBOX_DBUS_LEGACY_OBJECT "/org/openbmc/mboxd"
/* Command Args */ #include "hiomapd-state.h"
/* Resume */
#define RESUME_NUM_ARGS 1 struct transport_dbus_context {
#define RESUME_NOT_MODIFIED 0x00 struct ops_container w;
#define RESUME_FLASH_MODIFIED 0x01 struct mbox_context *context;
sd_bus *bus;
/* Response Args */ int dbus_fd;
/* Status */ };
#define DAEMON_STATE_NUM_ARGS 1
#define DAEMON_STATE_ACTIVE 0x00 /* Daemon Active */ static inline struct mbox_context *dctx_to_mctx(struct transport_dbus_context *dctx)
#define DAEMON_STATE_SUSPENDED 0x01 /* Daemon Suspended */ {
return dctx->context;
/* LPC State */ }
#define LPC_STATE_NUM_ARGS 1
#define LPC_STATE_INVALID 0x00 /* Invalid State */ static inline struct transport_dbus_context *
#define LPC_STATE_FLASH 0x01 /* LPC Maps Flash Directly */ container_to_dctx(struct ops_container *container)
#define LPC_STATE_MEM 0x02 /* LPC Maps Memory */ {
return container_of(container, struct transport_dbus_context, w);
}
#endif /* MBOX_DBUS_H */ #endif /* MBOX_DBUS_H */
#ifndef HIOMAPD_STATE_H
#define HIOMAPD_STATE_H
/* Command Args */
/* Resume */
#define RESUME_NUM_ARGS 1
#define RESUME_NOT_MODIFIED 0x00
#define RESUME_FLASH_MODIFIED 0x01
/* Response Args */
/* Status */
#define DAEMON_STATE_NUM_ARGS 1
#define DAEMON_STATE_ACTIVE 0x00 /* Daemon Active */
#define DAEMON_STATE_SUSPENDED 0x01 /* Daemon Suspended */
/* LPC State */
#define LPC_STATE_NUM_ARGS 1
#define LPC_STATE_INVALID 0x00 /* Invalid State */
#define LPC_STATE_FLASH 0x01 /* LPC Maps Flash Directly */
#define LPC_STATE_MEM 0x02 /* LPC Maps Memory */
#endif
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
#define LPC_CTRL_PATH "/dev/aspeed-lpc-ctrl" #define LPC_CTRL_PATH "/dev/aspeed-lpc-ctrl"
struct host_lpc_link_context {
int lpcfd;
};
int __lpc_dev_init(struct mbox_context *context, const char *path) int __lpc_dev_init(struct mbox_context *context, const char *path)
{ {
struct aspeed_lpc_ctrl_mapping map = { struct aspeed_lpc_ctrl_mapping map = {
...@@ -43,6 +47,13 @@ int __lpc_dev_init(struct mbox_context *context, const char *path) ...@@ -43,6 +47,13 @@ int __lpc_dev_init(struct mbox_context *context, const char *path)
.size = 0 .size = 0
}; };
int fd; int fd;
struct host_lpc_link_context *lctx = calloc(1,sizeof(*lctx));
if (!lctx) {
MSG_ERR("Couldn't allocate lpc link context\n");
return -ENOMEM;
}
context->host_link_ctx = lctx;
/* Open LPC Device */ /* Open LPC Device */
MSG_DBG("Opening %s\n", path); MSG_DBG("Opening %s\n", path);
...@@ -53,7 +64,7 @@ int __lpc_dev_init(struct mbox_context *context, const char *path) ...@@ -53,7 +64,7 @@ int __lpc_dev_init(struct mbox_context *context, const char *path)
return -errno; return -errno;
} }
context->fds[LPC_CTRL_FD].fd = fd; lctx->lpcfd = fd;
/* Find Size of Reserved Memory Region */ /* Find Size of Reserved Memory Region */
MSG_DBG("Getting buffer size...\n"); MSG_DBG("Getting buffer size...\n");
...@@ -86,10 +97,11 @@ int lpc_dev_init(struct mbox_context *context) ...@@ -86,10 +97,11 @@ int lpc_dev_init(struct mbox_context *context)
void lpc_dev_free(struct mbox_context *context) void lpc_dev_free(struct mbox_context *context)
{ {
struct host_lpc_link_context *lctx = context->host_link_ctx;
if (context->mem) { if (context->mem) {
munmap(context->mem, context->mem_size); munmap(context->mem, context->mem_size);
} }
close(context->fds[LPC_CTRL_FD].fd); close(lctx->lpcfd);
} }
/* /*
...@@ -100,6 +112,7 @@ void lpc_dev_free(struct mbox_context *context) ...@@ -100,6 +112,7 @@ void lpc_dev_free(struct mbox_context *context)
*/ */
int lpc_map_flash(struct mbox_context *context) int lpc_map_flash(struct mbox_context *context)
{ {
struct host_lpc_link_context *lctx = context->host_link_ctx;
struct aspeed_lpc_ctrl_mapping map = { struct aspeed_lpc_ctrl_mapping map = {
.window_type = ASPEED_LPC_CTRL_WINDOW_FLASH, .window_type = ASPEED_LPC_CTRL_WINDOW_FLASH,
.window_id = 0, /* Theres only one */ .window_id = 0, /* Theres only one */
...@@ -126,7 +139,7 @@ int lpc_map_flash(struct mbox_context *context) ...@@ -126,7 +139,7 @@ int lpc_map_flash(struct mbox_context *context)
MSG_INFO("Assuming %dMB of flash: HOST LPC 0x%08x\n", MSG_INFO("Assuming %dMB of flash: HOST LPC 0x%08x\n",
context->backend.flash_size >> 20, map.addr); context->backend.flash_size >> 20, map.addr);
if (ioctl(context->fds[LPC_CTRL_FD].fd, ASPEED_LPC_CTRL_IOCTL_MAP, &map) if (ioctl(lctx->lpcfd, ASPEED_LPC_CTRL_IOCTL_MAP, &map)
== -1) { == -1) {
MSG_ERR("Failed to point the LPC BUS at the actual flash: %s\n", MSG_ERR("Failed to point the LPC BUS at the actual flash: %s\n",
strerror(errno)); strerror(errno));
...@@ -150,6 +163,7 @@ int lpc_map_flash(struct mbox_context *context) ...@@ -150,6 +163,7 @@ int lpc_map_flash(struct mbox_context *context)
*/ */
int lpc_map_memory(struct mbox_context *context) int lpc_map_memory(struct mbox_context *context)
{ {
struct host_lpc_link_context *lctx = context->host_link_ctx;
struct aspeed_lpc_ctrl_mapping map = { struct aspeed_lpc_ctrl_mapping map = {
.window_type = ASPEED_LPC_CTRL_WINDOW_MEMORY, .window_type = ASPEED_LPC_CTRL_WINDOW_MEMORY,
.window_id = 0, /* There's only one */ .window_id = 0, /* There's only one */
...@@ -167,7 +181,7 @@ int lpc_map_memory(struct mbox_context *context) ...@@ -167,7 +181,7 @@ int lpc_map_memory(struct mbox_context *context)
context->mem, context->mem_size); context->mem, context->mem_size);
MSG_INFO("LPC address 0x%.8x\n", map.addr); MSG_INFO("LPC address 0x%.8x\n", map.addr);
if (ioctl(context->fds[LPC_CTRL_FD].fd, ASPEED_LPC_CTRL_IOCTL_MAP, if (ioctl(lctx->lpcfd, ASPEED_LPC_CTRL_IOCTL_MAP,
&map)) { &map)) {
MSG_ERR("Failed to point the LPC BUS to memory: %s\n", MSG_ERR("Failed to point the LPC BUS to memory: %s\n",
strerror(errno)); strerror(errno));
......
...@@ -24,17 +24,13 @@ ...@@ -24,17 +24,13 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <inttypes.h> #include <inttypes.h>
#include <systemd/sd-bus.h> #include <sys/epoll.h>
#include "config.h" #include "config.h"
#include "mboxd.h" #include "mboxd.h"
#include "common.h" #include "common.h"
#include "dbus.h"
#include "control_dbus.h"
#include "backend.h" #include "backend.h"
#include "lpc.h" #include "lpc.h"
#include "transport_mbox.h"
#include "transport_dbus.h"
#include "windows.h" #include "windows.h"
#include "vpnor/backend.h" #include "vpnor/backend.h"
...@@ -57,133 +53,33 @@ const char* USAGE = ...@@ -57,133 +53,33 @@ const char* USAGE =
"\t-f | --flash\t\tSize of flash in [K|M] bytes\n\n" "\t-f | --flash\t\tSize of flash in [K|M] bytes\n\n"
"\t-t | --trace\t\tFile to write trace data to (in blktrace format)\n\n"; "\t-t | --trace\t\tFile to write trace data to (in blktrace format)\n\n";
static int dbus_init(struct mbox_context *context,
const struct transport_ops **ops)
{
int rc;
rc = sd_bus_default_system(&context->bus);
if (rc < 0) {
MSG_ERR("Failed to connect to the system bus: %s\n",
strerror(-rc));
return rc;
}
rc = control_legacy_init(context);
if (rc < 0) {
MSG_ERR("Failed to initialise legacy DBus interface: %s\n",
strerror(-rc));
return rc;
}
rc = control_dbus_init(context);
if (rc < 0) {
MSG_ERR("Failed to initialise DBus control interface: %s\n",
strerror(-rc));
return rc;
}
rc = transport_dbus_init(context, ops);
if (rc < 0) {
MSG_ERR("Failed to initialise DBus protocol interface: %s\n",
strerror(-rc));
return rc;
}
rc = sd_bus_request_name(context->bus, MBOX_DBUS_NAME,
SD_BUS_NAME_ALLOW_REPLACEMENT |
SD_BUS_NAME_REPLACE_EXISTING);
if (rc < 0) {
MSG_ERR("Failed to request DBus name: %s\n", strerror(-rc));
return rc;
}
rc = sd_bus_get_fd(context->bus);
if (rc < 0) {
MSG_ERR("Failed to get bus fd: %s\n", strerror(-rc));
return rc;
}
context->fds[DBUS_FD].fd = rc;
return 0;
}
static void dbus_free(struct mbox_context *context)
{
transport_dbus_free(context);
control_dbus_free(context);
control_legacy_free(context);
sd_bus_unref(context->bus);
}
static int poll_loop(struct mbox_context *context) static int poll_loop(struct mbox_context *context)
{ {
int rc = 0, i; int rc = 0, i;
int count;
/* Set POLLIN on polling file descriptors */ /* This is a low throughput api, 0x10 events is huge,
for (i = 0; i < POLL_FDS; i++) { * one would probably be sufficent.*/
context->fds[i].events = POLLIN; struct epoll_event evt[0x10] = { 0 };
} struct ops_container *w;
while (1) { while (true) {
rc = poll(context->fds, POLL_FDS, -1); count = epoll_wait(context->epollfd, evt, 0x10, -1);
if (count < 0)
if (rc < 0) { /* Error */ {
MSG_ERR("Error from poll(): %s\n", strerror(errno)); MSG_ERR("Error from epoll_wait(): %s\n", strerror(errno));
break; /* This should mean we clean up nicely */ continue;
} }
for (i = 0; i < count; i++)
/* Event on Polled File Descriptor - Handle It */ {
if (context->fds[SIG_FD].revents & POLLIN) { /* Signal */ w = evt[i].data.ptr;
struct signalfd_siginfo info = { 0 }; if (w[0].ops->event(w, evt + i) < 0)
MSG_ERR("Error in event dispatch\n");
rc = read(context->fds[SIG_FD].fd, (void *) &info, }
sizeof(info));
if (rc != sizeof(info)) {
MSG_ERR("Error reading signal event: %s\n",
strerror(errno));
}
MSG_DBG("Received signal: %d\n", info.ssi_signo);
switch (info.ssi_signo) {
case SIGINT:
case SIGTERM:
MSG_INFO("Caught Signal - Exiting...\n");
context->terminate = true;
break;
case SIGHUP:
rc = protocol_reset(context);
if (rc < 0) {
MSG_ERR("Failed to reset on SIGHUP\n");
}
break;
default:
MSG_ERR("Unhandled Signal: %d\n",
info.ssi_signo);
break;
}
}
if (context->fds[DBUS_FD].revents & POLLIN) { /* DBUS */
while ((rc = sd_bus_process(context->bus, NULL)) > 0) {
MSG_DBG("DBUS Event\n");
}
if (rc < 0) {
MSG_ERR("Error handling DBUS event: %s\n",
strerror(-rc));
}
}
if (context->terminate) { if (context->terminate) {
break; /* This should mean we clean up nicely */ break; /* This should mean we clean up nicely */
} }
if (context->fds[MBOX_FD].revents & POLLIN) { /* MBOX */ }
MSG_DBG("MBOX Event\n");
rc = transport_mbox_dispatch(context);
if (rc < 0) {
MSG_ERR("Error handling MBOX event\n");
}
}
}
rc = protocol_reset(context); rc = protocol_reset(context);
if (rc < 0) { if (rc < 0) {
...@@ -193,32 +89,6 @@ static int poll_loop(struct mbox_context *context) ...@@ -193,32 +89,6 @@ static int poll_loop(struct mbox_context *context)
return rc; return rc;
} }
static int init_signals(struct mbox_context *context, sigset_t *set)
{
int rc;
/* Block SIGHUPs, SIGTERMs and SIGINTs */
sigemptyset(set);
sigaddset(set, SIGHUP);
sigaddset(set, SIGINT);
sigaddset(set, SIGTERM);
rc = sigprocmask(SIG_BLOCK, set, NULL);
if (rc < 0) {
MSG_ERR("Failed to set SIG_BLOCK mask %s\n", strerror(errno));
return rc;
}
/* Get Signal File Descriptor */
rc = signalfd(-1, set, SFD_NONBLOCK);
if (rc < 0) {
MSG_ERR("Failed to get signalfd %s\n", strerror(errno));
return rc;
}
context->fds[SIG_FD].fd = rc;
return 0;
}
static void usage(const char *name) static void usage(const char *name)
{ {
printf(USAGE, name); printf(USAGE, name);
...@@ -387,14 +257,20 @@ static int mboxd_backend_init(struct mbox_context *context) ...@@ -387,14 +257,20 @@ static int mboxd_backend_init(struct mbox_context *context)
return rc; return rc;
} }
extern void *__start_ops_array;
extern void *__stop_ops_array;
static struct transport_ops **ops_array =
(struct transport_ops **)&__start_ops_array;
static size_t ops_array_size;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
const struct transport_ops *mbox_ops, *dbus_ops;
struct mbox_context *context; struct mbox_context *context;
bool have_transport_mbox;
char *name = argv[0]; char *name = argv[0];
sigset_t set;
int rc, i; int rc, i;
ops_array_size =
((struct transport_ops **)&__stop_ops_array) -
((struct transport_ops **)&__start_ops_array);
context = calloc(1, sizeof(*context)); context = calloc(1, sizeof(*context));
if (!context) { if (!context) {
...@@ -408,17 +284,10 @@ int main(int argc, char **argv) ...@@ -408,17 +284,10 @@ int main(int argc, char **argv)
exit(0); exit(0);
} }
for (i = 0; i < TOTAL_FDS; i++) { context->epollfd = epoll_create1(EPOLL_CLOEXEC);
context->fds[i].fd = -1;
}
MSG_INFO("Starting Daemon\n"); MSG_INFO("Starting Daemon\n");
rc = init_signals(context, &set);
if (rc) {
goto cleanup_context;
}
rc = mboxd_backend_init(context); rc = mboxd_backend_init(context);
if (rc) { if (rc) {
goto cleanup_context; goto cleanup_context;
...@@ -429,16 +298,6 @@ int main(int argc, char **argv) ...@@ -429,16 +298,6 @@ int main(int argc, char **argv)
goto cleanup_backend; goto cleanup_backend;
} }
rc = transport_mbox_init(context, &mbox_ops);
/* TODO: Think about whether we could use a less branch-y strategy */
have_transport_mbox = rc == 0;
if (!have_transport_mbox) {
/* Disable MBOX for poll()ing purposes */
context->fds[MBOX_FD].fd = -1;
MSG_DBG("Failed to initialise MBOX transport: %d\n", rc);
MSG_INFO("MBOX transport unavailable\n");
}
rc = lpc_dev_init(context); rc = lpc_dev_init(context);
if (rc) { if (rc) {
goto cleanup_mbox; goto cleanup_mbox;
...@@ -450,10 +309,8 @@ int main(int argc, char **argv) ...@@ -450,10 +309,8 @@ int main(int argc, char **argv)
goto cleanup_lpc; goto cleanup_lpc;
} }
rc = dbus_init(context, &dbus_ops); for (i = 0; i < ops_array_size; i++)
if (rc) { ops_array[i]->init(context, ops_array[i]);
goto cleanup_windows;
}
/* Set the LPC bus mapping */ /* Set the LPC bus mapping */
__protocol_reset(context); __protocol_reset(context);
...@@ -462,19 +319,6 @@ int main(int argc, char **argv) ...@@ -462,19 +319,6 @@ int main(int argc, char **argv)
context->bmc_events |= BMC_EVENT_DAEMON_READY; context->bmc_events |= BMC_EVENT_DAEMON_READY;
context->bmc_events |= BMC_EVENT_PROTOCOL_RESET; context->bmc_events |= BMC_EVENT_PROTOCOL_RESET;
/* Alert on all supported transports, as required */
if (have_transport_mbox) {
rc = protocol_events_put(context, mbox_ops);
if (rc) {
goto cleanup;
}
}
rc = protocol_events_put(context, dbus_ops);
if (rc) {
goto cleanup;
}
MSG_INFO("Entering Polling Loop\n"); MSG_INFO("Entering Polling Loop\n");
rc = poll_loop(context); rc = poll_loop(context);
...@@ -484,23 +328,14 @@ int main(int argc, char **argv) ...@@ -484,23 +328,14 @@ int main(int argc, char **argv)
context->bmc_events &= ~BMC_EVENT_DAEMON_READY; context->bmc_events &= ~BMC_EVENT_DAEMON_READY;
context->bmc_events |= BMC_EVENT_PROTOCOL_RESET; context->bmc_events |= BMC_EVENT_PROTOCOL_RESET;
/* Alert on all supported transports, as required */ /* I think we can skip all transport that are not the active
if (have_transport_mbox) { * transport */
protocol_events_put(context, mbox_ops);
}
protocol_events_put(context, dbus_ops);
cleanup:
dbus_free(context);
cleanup_windows: cleanup_windows:
windows_free(context); windows_free(context);
cleanup_lpc: cleanup_lpc:
lpc_dev_free(context); lpc_dev_free(context);
cleanup_mbox: cleanup_mbox:
if (have_transport_mbox) {
transport_mbox_free(context);
}
protocol_free(context); protocol_free(context);
cleanup_backend: cleanup_backend:
backend_free(&context->backend); backend_free(&context->backend);
...@@ -512,3 +347,109 @@ cleanup_context: ...@@ -512,3 +347,109 @@ cleanup_context:
return rc; return rc;
} }
/* Singal 'transport' */
struct signal_context {
struct mbox_context *context;
struct ops_container w;
int signal_fd;
};
static inline struct signal_context* container_to_sctx(struct ops_container *container)
{
return container_of(container, struct signal_context, w);
}
static int init_signals(struct mbox_context *context,
struct transport_ops *ops)
{
int rc;
sigset_t set;
struct signal_context *sctx = calloc(1, sizeof(*sctx));
if (!sctx) {
MSG_ERR("Failed to allocate signal context\n");
return -ENOMEM;
}
sctx->context = context;
sctx->w.ops = ops;
/* Block SIGHUPs, SIGTERMs and SIGINTs */
sigemptyset(&set);
sigaddset(&set, SIGHUP);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTERM);
rc = sigprocmask(SIG_BLOCK, &set, NULL);
if (rc < 0) {
MSG_ERR("Failed to set SIG_BLOCK mask %s\n", strerror(errno));
free(sctx);
return rc;
}
/* Get Signal File Descriptor */
rc = signalfd(-1, &set, SFD_NONBLOCK);
if (rc < 0) {
MSG_ERR("Failed to get signalfd %s\n", strerror(errno));
free(sctx);
return rc;
}
sctx->signal_fd = rc;
register_event_fd(sctx->signal_fd, context, &sctx->w);
return 0;
}
static int signal_event(struct ops_container *container,
struct epoll_event *evt)
{
struct signal_context *sctx = container_to_sctx(container);
struct mbox_context *context = sctx->context;
struct signalfd_siginfo info = { 0 };
int rc;
if (!(evt->events & EPOLLIN))
{
MSG_ERR("Signal event, but no event ready\n");
return -EINVAL;
}
rc = read(sctx->signal_fd, (void *) &info,
sizeof(info));
if (rc != sizeof(info)) {
MSG_ERR("Error reading signal event: %s\n",
strerror(errno));
return rc;
}
MSG_DBG("Received signal: %d\n", info.ssi_signo);
switch (info.ssi_signo) {
case SIGINT:
case SIGTERM:
MSG_INFO("Caught Signal - Exiting...\n");
context->terminate = true;
break;
case SIGHUP:
rc = protocol_reset(context);
if (rc < 0) {