diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c index ed8f408..3ad3553 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,7 +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 = init_connection(); + int socket_fd; + +try_again: + socket_fd = init_connection(); if(!socket_fd) { return NULL; } @@ -115,17 +119,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; }