@@ -335,8 +335,7 @@ int tracecmd_msg_finish_sending_metadata(struct tracecmd_msg_handle *msg_handle)
void tracecmd_msg_send_close_msg(struct tracecmd_msg_handle *msg_handle);
/* for server */
-int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle,
- int *pagesize);
+int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle);
int tracecmd_msg_send_port_array(struct tracecmd_msg_handle *msg_handle,
int *ports);
int tracecmd_msg_collect_metadata(struct tracecmd_msg_handle *msg_handle, int ofd);
@@ -372,12 +372,12 @@ static int open_udp(const char *node, const char *port, int *pid,
return num_port;
}
-static int communicate_with_client(struct tracecmd_msg_handle *msg_handle,
- int *pagesize)
+static int communicate_with_client(struct tracecmd_msg_handle *msg_handle)
{
char *last_proto = NULL;
char buf[BUFSIZ];
char *option;
+ int pagesize = 0;
int options;
int size;
int cpus;
@@ -438,7 +438,7 @@ static int communicate_with_client(struct tracecmd_msg_handle *msg_handle,
msg_handle->version = V2_PROTOCOL;
/* read the CPU count, the page size, and options */
- if (tracecmd_msg_initial_setting(msg_handle, pagesize) < 0)
+ if ((pagesize = tracecmd_msg_initial_setting(msg_handle)) < 0)
goto out;
} else {
/* The client is using the v1 protocol */
@@ -455,10 +455,10 @@ static int communicate_with_client(struct tracecmd_msg_handle *msg_handle,
/** ERROR **/
goto out;
- *pagesize = atoi(buf);
+ pagesize = atoi(buf);
- plog("pagesize=%d\n", *pagesize);
- if (*pagesize <= 0)
+ plog("pagesize=%d\n", pagesize);
+ if (pagesize <= 0)
goto out;
/* Now the number of options */
@@ -508,7 +508,7 @@ static int communicate_with_client(struct tracecmd_msg_handle *msg_handle,
if (msg_handle->flags & TRACECMD_MSG_FL_USE_TCP)
plog("Using TCP for live connection\n");
- ret = 0;
+ ret = pagesize;
out:
free(last_proto);
@@ -558,6 +558,9 @@ static int *create_all_readers(const char *node, const char *port,
int cpu;
int pid;
+ if (!pagesize)
+ return NULL;
+
port_array = malloc(sizeof(int) * cpus);
if (!port_array)
return NULL;
@@ -688,9 +691,9 @@ static int process_client(struct tracecmd_msg_handle *msg_handle,
int ofd;
int ret;
- ret = communicate_with_client(msg_handle, &pagesize);
- if (ret < 0)
- return ret;
+ pagesize = communicate_with_client(msg_handle);
+ if (pagesize < 0)
+ return pagesize;
ofd = create_client_file(node, port);
@@ -478,11 +478,11 @@ static void error_operation_for_server(struct tracecmd_msg *msg)
#define MAX_OPTION_SIZE 4096
-int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle,
- int *pagesize)
+int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle)
{
struct tracecmd_msg_opt *opt;
struct tracecmd_msg msg;
+ int pagesize;
int options, i, s;
int cpus;
int ret;
@@ -512,9 +512,9 @@ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle,
msg_handle->cpu_count = cpus;
- *pagesize = ntohl(msg.tinit.page_size);
- plog("pagesize=%d\n", *pagesize);
- if (*pagesize <= 0) {
+ pagesize = ntohl(msg.tinit.page_size);
+ plog("pagesize=%d\n", pagesize);
+ if (pagesize <= 0) {
ret = -EINVAL;
goto error;
}
@@ -550,7 +550,7 @@ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle,
}
}
- return 0;
+ return pagesize;
error:
error_operation_for_server(&msg);