diff --git a/mboxd.c b/mboxd.c index 637f416ca18d06706b3dbbc31c7f2fde73a8780c..c7f7d33c0585e4c09a28f3e90dcbcde3f37e672d 100644 --- a/mboxd.c +++ b/mboxd.c @@ -391,6 +391,7 @@ int main(int argc, char **argv) { const struct transport_ops *mbox_ops, *dbus_ops; struct mbox_context *context; + bool have_transport_mbox; char *name = argv[0]; sigset_t set; int rc, i; @@ -429,8 +430,13 @@ int main(int argc, char **argv) } rc = transport_mbox_init(context, &mbox_ops); - if (rc) { - goto cleanup_protocol; + /* 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); @@ -456,10 +462,12 @@ int main(int argc, char **argv) context->bmc_events |= BMC_EVENT_DAEMON_READY; context->bmc_events |= BMC_EVENT_PROTOCOL_RESET; - /* Alert on all supported transports */ - rc = protocol_events_put(context, mbox_ops); - if (rc) { - goto cleanup; + /* 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); @@ -476,8 +484,11 @@ int main(int argc, char **argv) context->bmc_events &= ~BMC_EVENT_DAEMON_READY; context->bmc_events |= BMC_EVENT_PROTOCOL_RESET; - /* Alert on all supported transports */ - protocol_events_put(context, mbox_ops); + /* Alert on all supported transports, as required */ + if (have_transport_mbox) { + protocol_events_put(context, mbox_ops); + } + protocol_events_put(context, dbus_ops); cleanup: @@ -487,8 +498,9 @@ cleanup_windows: cleanup_lpc: lpc_dev_free(context); cleanup_mbox: - transport_mbox_free(context); -cleanup_protocol: + if (have_transport_mbox) { + transport_mbox_free(context); + } protocol_free(context); cleanup_backend: backend_free(&context->backend); diff --git a/test/mbox.c b/test/mbox.c index 55af00c9502008e69e736ec4d53d176bf6ea9ccf..c224b8450e8c8786e43456afba48addcd6fb572a 100644 --- a/test/mbox.c +++ b/test/mbox.c @@ -211,11 +211,13 @@ void cleanup(void) tmpf_destroy(&test.lpc); } -int __transport_mbox_init(struct mbox_context *context, const char *path); +int __transport_mbox_init(struct mbox_context *context, const char *path, + const struct transport_ops **ops); int __lpc_dev_init(struct mbox_context *context, const char *path); struct mbox_context *mbox_create_frontend_context(int n_windows, size_t len) { + const struct transport_ops *ops; struct mtd_info_user mtd_info; int rc; @@ -242,7 +244,8 @@ struct mbox_context *mbox_create_frontend_context(int n_windows, size_t len) * /dev/null and replace it with our own fd for mbox device emulation * by the test framework. */ - __transport_mbox_init(&test.context, "/dev/null"); + __transport_mbox_init(&test.context, "/dev/null", &ops); + test.context.transport = ops; rc = close(test.context.fds[MBOX_FD].fd); assert(rc == 0); test.context.fds[MBOX_FD].fd = test.mbox.fd; diff --git a/transport_dbus.c b/transport_dbus.c index b6eb0e1b477f969a956d17458d37283cf575f194..18cd0d07eac82a762f18ab7b17c08e2b58f0676f 100644 --- a/transport_dbus.c +++ b/transport_dbus.c @@ -526,6 +526,8 @@ int transport_dbus_init(struct mbox_context *context, return rc; } + context->transport = &transport_dbus_ops; + if (ops) { *ops = &transport_dbus_ops; } diff --git a/transport_mbox.c b/transport_mbox.c index 3d718208175eeb2a450fe56a4f2e429e8b86824d..2759fa5e1cfbe8781406898966c886388df1008c 100644 --- a/transport_mbox.c +++ b/transport_mbox.c @@ -646,16 +646,15 @@ int transport_mbox_dispatch(struct mbox_context *context) return handle_mbox_req(context, &req); } -int __transport_mbox_init(struct mbox_context *context, const char *path) +int __transport_mbox_init(struct mbox_context *context, const char *path, + const struct transport_ops **ops) { int fd; - context->transport = &transport_mbox_ops; - /* Open MBOX Device */ fd = open(path, O_RDWR | O_NONBLOCK); if (fd < 0) { - MSG_ERR("Couldn't open %s with flags O_RDWR: %s\n", + MSG_INFO("Couldn't open %s with flags O_RDWR: %s\n", path, strerror(errno)); return -errno; } @@ -663,6 +662,10 @@ int __transport_mbox_init(struct mbox_context *context, const char *path) context->fds[MBOX_FD].fd = fd; + if (ops) { + *ops = &transport_mbox_ops; + } + return 0; } @@ -671,14 +674,10 @@ int transport_mbox_init(struct mbox_context *context, { int rc; - rc = __transport_mbox_init(context, MBOX_HOST_PATH); + rc = __transport_mbox_init(context, MBOX_HOST_PATH, ops); if (rc) return rc; - if (ops) { - *ops = &transport_mbox_ops; - } - return 0; }