From 9b004c6628503c15c7b9e8c66e62028123924aa1 Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Wed, 26 Jan 2022 08:25:58 -0500 Subject: [PATCH 1/2] Ensure that we get all of a unix message receive data with MSG_TRUNC set so that we can check to see that we got everything the server sent us. Signed-off-by: Neil Horman --- ui/irqbalance-ui.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c index ed8f408..959b312 100644 --- a/ui/irqbalance-ui.c +++ b/ui/irqbalance-ui.c @@ -21,6 +21,7 @@ GList *tree = NULL; setup_t setup; GMainLoop *main_loop; int is_tree = 1; +static int default_bufsz = 8192; struct msghdr * create_credentials_msg() { @@ -103,6 +104,7 @@ char * get_data(char *string) /* Send "setup" to get sleep interval, banned IRQs and banned CPUs, * "stats" to get CPU tree statistics */ +try_again: int socket_fd = init_connection(); if(!socket_fd) { return NULL; @@ -115,17 +117,18 @@ char * get_data(char *string) msg->msg_iov = &iov; sendmsg(socket_fd, msg, 0); - /* - * This is just...horrible. Mental note to replace this - * With a select, ioctl to determine size, and malloc based - * on that - */ - char *data = malloc(8192); - int len = recv(socket_fd, data, 8192, 0); + char *data = malloc(default_bufsz); + int len = recv(socket_fd, data, default_bufsz, MSG_TRUNC); close(socket_fd); data[len] = '\0'; free(msg->msg_control); free(msg); + if (len >= default_bufsz) { + /* msg was truncated, increase bufsz and try again */ + default_bufsz += 8192; + free(data); + goto try_again; + } return data; } From 0f594a6f19b38dd595b89636317d82de0f841522 Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Wed, 26 Jan 2022 09:26:38 -0500 Subject: [PATCH 2/2] Separate variable declaration from assignment We need to do this to allow for the label placement on older gcc versions Signed-off-by: Neil Horman --- ui/irqbalance-ui.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c index 959b312..3ad3553 100644 --- a/ui/irqbalance-ui.c +++ b/ui/irqbalance-ui.c @@ -104,8 +104,10 @@ char * get_data(char *string) /* Send "setup" to get sleep interval, banned IRQs and banned CPUs, * "stats" to get CPU tree statistics */ + int socket_fd; + try_again: - int socket_fd = init_connection(); + socket_fd = init_connection(); if(!socket_fd) { return NULL; }