Fix bug in the mctp-demux-daemon client management logic
When there were multiple clients running at the same time,
and disconnecting at random times, it could happen that the
MCTP clients socket array got misaligned, causing still
active clients to get their socket removed prematurely.
While the MCTP demux daemon already had logic in place to
ensure the socket array got realigned whenever a client was
either added or removed, there was one corner case it didn't
cover.
This bug was discovered when running with serial binding.
However likely an issue for all binding types.
Change-Id: Idc1a7f10806b256a0b5a3d02ef5f36c04b714b93
Signed-off-by: Ken Wahid <kw@napatech.com>
diff --git a/utils/mctp-demux-daemon.c b/utils/mctp-demux-daemon.c
index 7357d43..f65f4da 100644
--- a/utils/mctp-demux-daemon.c
+++ b/utils/mctp-demux-daemon.c
@@ -461,6 +461,7 @@
bool clients_changed = false;
sigset_t mask;
int rc, i;
+ int n_clients;
ctx->pollfds = malloc(FD_NR * sizeof(struct pollfd));
@@ -534,6 +535,7 @@
}
}
+ n_clients = ctx->n_clients;
if (ctx->pollfds[FD_BINDING].revents) {
rc = 0;
if (ctx->binding->process)
@@ -541,6 +543,16 @@
if (rc)
break;
}
+ if (n_clients != ctx->n_clients) {
+ /*
+ * Clients (i.e. sockets) were removed in the binding->process() function
+ * call above. More specifically in function rx_message(), invoked through
+ * the binding->process() call.
+ * We must go back to the top of the loop to realign the pollfds sockets array
+ */
+ clients_changed = true;
+ continue;
+ }
for (i = 0; i < ctx->n_clients; i++) {
if (!ctx->pollfds[FD_NR + i].revents)