demux-daemon: Add a 'null' binding option
For cases where we don't have a specific hardware configuration
available (eg., a platform-independent OpenBMC recipe), we want a
provision to run the demux daemon without specific hardware
dependencies.
This change introduces a null binding for mctp-demux-daemon, in order to
allow a hardware-neutral daemon process to be run.
Change-Id: I1d9e66f3c4b636f9160eb2fa31d547ca4add7f7a
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/utils/mctp-demux-daemon.c b/utils/mctp-demux-daemon.c
index 96d9753..eb7121b 100644
--- a/utils/mctp-demux-daemon.c
+++ b/utils/mctp-demux-daemon.c
@@ -19,6 +19,7 @@
#include "libmctp-astlpc.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#define __unused __attribute__((unused))
static const mctp_eid_t local_eid_default = 8;
static char sockname[] = "\0mctp-mux";
@@ -124,6 +125,18 @@
}
+static int binding_null_init(struct mctp *mctp __unused,
+ struct binding *binding __unused,
+ mctp_eid_t eid __unused,
+ int n_params, char * const *params __unused)
+{
+ if (n_params != 0) {
+ warnx("null binding doesn't accept parameters");
+ return -1;
+ }
+ return 0;
+}
+
static int binding_serial_init(struct mctp *mctp, struct binding *binding,
mctp_eid_t eid, int n_params, char * const *params)
{
@@ -197,6 +210,10 @@
struct binding bindings[] = {
{
+ .name = "null",
+ .init = binding_null_init,
+ },
+ {
.name = "serial",
.init = binding_serial_init,
.get_fd = binding_serial_get_fd,
@@ -384,9 +401,14 @@
ctx->pollfds = malloc(FD_NR * sizeof(struct pollfd));
- ctx->pollfds[FD_BINDING].fd =
- ctx->binding->get_fd(ctx->binding);
- ctx->pollfds[FD_BINDING].events = POLLIN;
+ if (ctx->binding->get_fd) {
+ ctx->pollfds[FD_BINDING].fd =
+ ctx->binding->get_fd(ctx->binding);
+ ctx->pollfds[FD_BINDING].events = POLLIN;
+ } else {
+ ctx->pollfds[FD_BINDING].fd = -1;
+ ctx->pollfds[FD_BINDING].events = 0;
+ }
ctx->pollfds[FD_SOCKET].fd = ctx->sock;
ctx->pollfds[FD_SOCKET].events = POLLIN;
@@ -419,7 +441,9 @@
continue;
if (ctx->pollfds[FD_BINDING].revents) {
- rc = ctx->binding->process(ctx->binding);
+ rc = 0;
+ if (ctx->binding->process)
+ rc = ctx->binding->process(ctx->binding);
if (rc)
break;
}