@@ -297,7 +297,7 @@ void tracecmd_disable_tracing(void);
void tracecmd_enable_tracing(void);
/* for clients */
-int tracecmd_msg_send_init_data(int fd, int total_cpus);
+int tracecmd_msg_send_init_data(int fd, int total_cpus, int **client_ports);
int tracecmd_msg_metadata_send(int fd, const char *buf, int size);
int tracecmd_msg_finish_sending_metadata(int fd);
void tracecmd_msg_send_close_msg(void);
@@ -68,7 +68,6 @@ bool use_tcp;
/* for client */
static int psfd;
unsigned int page_size;
-int *client_ports;
/* for server */
bool done;
@@ -367,13 +366,16 @@ static int tracecmd_msg_wait_for_msg(int fd, struct tracecmd_msg *msg)
return 0;
}
-int tracecmd_msg_send_init_data(int fd, int total_cpus)
+int tracecmd_msg_send_init_data(int fd, int total_cpus, int **client_ports)
{
struct tracecmd_msg send_msg;
struct tracecmd_msg recv_msg;
+ int *ports;
int i, cpus;
int ret;
+ *client_ports = NULL;
+
tracecmd_msg_init(MSG_TINIT, &send_msg);
ret = make_tinit(&send_msg, total_cpus);
if (ret < 0)
@@ -391,9 +393,11 @@ int tracecmd_msg_send_init_data(int fd, int total_cpus)
return -EINVAL;
cpus = ntohl(recv_msg.rinit.cpus);
- client_ports = malloc_or_die(sizeof(int) * cpus);
+ ports = malloc_or_die(sizeof(int) * cpus);
for (i = 0; i < cpus; i++)
- client_ports[i] = ntohl(recv_msg.port_array[i]);
+ ports[i] = ntohl(recv_msg.port_array[i]);
+
+ *client_ports = ports;
return 0;
}
@@ -15,7 +15,6 @@ extern bool use_tcp;
/* for client */
extern unsigned int page_size;
-extern int *client_ports;
/* for server */
extern bool done;
@@ -88,6 +88,7 @@ static int buffers;
static int clear_function_filters;
static char *host;
+static int *client_ports;
static int sfd;
static struct tracecmd_output *network_handle;
@@ -2756,7 +2757,7 @@ static void communicate_with_listener_v1(int fd)
static void communicate_with_listener_v2(int fd)
{
- if (tracecmd_msg_send_init_data(fd, cpu_count) < 0)
+ if (tracecmd_msg_send_init_data(fd, cpu_count, &client_ports) < 0)
die("Cannot communicate with server");
}