Merge pull request #198 from Irqbalance/unix_trunc
Ensure that we get all of a unix message
This commit is contained in:
commit
b3adb5fd14
|
@ -21,6 +21,7 @@ GList *tree = NULL;
|
||||||
setup_t setup;
|
setup_t setup;
|
||||||
GMainLoop *main_loop;
|
GMainLoop *main_loop;
|
||||||
int is_tree = 1;
|
int is_tree = 1;
|
||||||
|
static int default_bufsz = 8192;
|
||||||
|
|
||||||
struct msghdr * create_credentials_msg()
|
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,
|
/* Send "setup" to get sleep interval, banned IRQs and banned CPUs,
|
||||||
* "stats" to get CPU tree statistics
|
* "stats" to get CPU tree statistics
|
||||||
*/
|
*/
|
||||||
int socket_fd = init_connection();
|
int socket_fd;
|
||||||
|
|
||||||
|
try_again:
|
||||||
|
socket_fd = init_connection();
|
||||||
if(!socket_fd) {
|
if(!socket_fd) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -115,17 +119,18 @@ char * get_data(char *string)
|
||||||
msg->msg_iov = &iov;
|
msg->msg_iov = &iov;
|
||||||
sendmsg(socket_fd, msg, 0);
|
sendmsg(socket_fd, msg, 0);
|
||||||
|
|
||||||
/*
|
char *data = malloc(default_bufsz);
|
||||||
* This is just...horrible. Mental note to replace this
|
int len = recv(socket_fd, data, default_bufsz, MSG_TRUNC);
|
||||||
* With a select, ioctl to determine size, and malloc based
|
|
||||||
* on that
|
|
||||||
*/
|
|
||||||
char *data = malloc(8192);
|
|
||||||
int len = recv(socket_fd, data, 8192, 0);
|
|
||||||
close(socket_fd);
|
close(socket_fd);
|
||||||
data[len] = '\0';
|
data[len] = '\0';
|
||||||
free(msg->msg_control);
|
free(msg->msg_control);
|
||||||
free(msg);
|
free(msg);
|
||||||
|
if (len >= default_bufsz) {
|
||||||
|
/* msg was truncated, increase bufsz and try again */
|
||||||
|
default_bufsz += 8192;
|
||||||
|
free(data);
|
||||||
|
goto try_again;
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue