diff mbox series

[v4,4/8] trace-cmd: Use unsigned int for trace-cmd client ports

Message ID 20190116134307.4185-5-kaslevs@vmware.com (mailing list archive)
State Accepted
Headers show
Series Add VM kernel tracing over vsock sockets | expand

Commit Message

Slavomir Kaslev Jan. 16, 2019, 1:43 p.m. UTC
From: Tzvetomir Stoyanov <tstoyanov@vmware.com>

By definition, communication ports used by trace-cmd clients
are 32 bit unsigned integers. These ports are generated randomly,
and in some implementations can overlap the signed integer range.
This patch converts all client ports in trace-cmd to be unsigned
32 bit integers.

Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Signed-off-by: Slavomir Kaslev <kaslevs@vmware.com>
---
 include/trace-cmd/trace-cmd.h | 2 +-
 tracecmd/trace-msg.c          | 4 ++--
 tracecmd/trace-record.c       | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index ff4f0f7..8b43462 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -322,7 +322,7 @@  void tracecmd_msg_handle_close(struct tracecmd_msg_handle *msg_handle);
 
 /* for clients */
 int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle,
-				int **client_ports);
+				unsigned int **client_ports);
 int tracecmd_msg_data_send(struct tracecmd_msg_handle *msg_handle,
 			       const char *buf, int size);
 int tracecmd_msg_finish_sending_data(struct tracecmd_msg_handle *msg_handle);
diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c
index edde582..529ae2a 100644
--- a/tracecmd/trace-msg.c
+++ b/tracecmd/trace-msg.c
@@ -386,12 +386,12 @@  static int tracecmd_msg_wait_for_msg(int fd, struct tracecmd_msg *msg)
 }
 
 int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle,
-				int **client_ports)
+				unsigned int **client_ports)
 {
 	struct tracecmd_msg send_msg;
 	struct tracecmd_msg recv_msg;
 	int fd = msg_handle->fd;
-	int *ports;
+	unsigned int *ports;
 	int i, cpus;
 	int ret;
 
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index a8c3464..3034a4b 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -74,7 +74,7 @@  static int buffers;
 static int clear_function_filters;
 
 static char *host;
-static int *client_ports;
+static unsigned int *client_ports;
 static int sfd;
 
 /* Max size to let a per cpu file get */
@@ -2545,7 +2545,7 @@  static void connect_port(int cpu)
 	int s;
 	char buf[BUFSIZ];
 
-	snprintf(buf, BUFSIZ, "%d", client_ports[cpu]);
+	snprintf(buf, BUFSIZ, "%u", client_ports[cpu]);
 
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_UNSPEC;
@@ -2755,7 +2755,7 @@  static void communicate_with_listener_v1(struct tracecmd_msg_handle *msg_handle)
 		/* No options */
 		write(msg_handle->fd, "0", 2);
 
-	client_ports = malloc(sizeof(int) * local_cpu_count);
+	client_ports = malloc(local_cpu_count * sizeof(*client_ports));
 	if (!client_ports)
 		die("Failed to allocate client ports for %d cpus", local_cpu_count);