aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <rostedt@goodmis.org>2010-10-08 22:12:48 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-10-08 22:12:48 -0400
commitc66f63dbf993d8045bddf6551cdfeee29a309ff4 (patch)
tree66483c7b30cca418c292f832695e9f5c4e8e4bed
parentcb874a7384e5178602386515e18f437f3a864de5 (diff)
trace-cmd/listen: Force search of unique port
On some systems, the code to find a unique udp port may give a invalid success of the previous port. Which causes two child process to listen to the same port, and makes one of them fail. Force the start of the port search to the port after the last port found, to prevent the same port from being used by two listeners. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-listen.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/trace-listen.c b/trace-listen.c
index e8c9ba9..e60c96b 100644
--- a/trace-listen.c
+++ b/trace-listen.c
@@ -231,13 +231,13 @@ static void process_udp_child(int sfd, const char *host, const char *port,
231#define MAX_PORT_SEARCH 6000 231#define MAX_PORT_SEARCH 6000
232 232
233static int open_udp(const char *node, const char *port, int *pid, 233static int open_udp(const char *node, const char *port, int *pid,
234 int cpu, int pagesize) 234 int cpu, int pagesize, int start_port)
235{ 235{
236 struct addrinfo hints; 236 struct addrinfo hints;
237 struct addrinfo *result, *rp; 237 struct addrinfo *result, *rp;
238 int sfd, s; 238 int sfd, s;
239 char buf[BUFSIZ]; 239 char buf[BUFSIZ];
240 int num_port = START_PORT_SEARCH; 240 int num_port = start_port;
241 241
242 again: 242 again:
243 snprintf(buf, BUFSIZ, "%d", num_port); 243 snprintf(buf, BUFSIZ, "%d", num_port);
@@ -293,6 +293,7 @@ static void process_client(const char *node, const char *port, int fd)
293 int *port_array; 293 int *port_array;
294 int *pid_array; 294 int *pid_array;
295 int pagesize; 295 int pagesize;
296 int start_port;
296 int udp_port; 297 int udp_port;
297 int options; 298 int options;
298 int size; 299 int size;
@@ -379,13 +380,17 @@ static void process_client(const char *node, const char *port, int fd)
379 pid_array = malloc_or_die(sizeof(int) * cpus); 380 pid_array = malloc_or_die(sizeof(int) * cpus);
380 memset(pid_array, 0, sizeof(int) * cpus); 381 memset(pid_array, 0, sizeof(int) * cpus);
381 382
383 start_port = START_PORT_SEARCH;
384
382 /* Now create a UDP port for each CPU */ 385 /* Now create a UDP port for each CPU */
383 for (cpu = 0; cpu < cpus; cpu++) { 386 for (cpu = 0; cpu < cpus; cpu++) {
384 udp_port = open_udp(node, port, &pid, cpu, pagesize); 387 udp_port = open_udp(node, port, &pid, cpu, pagesize, start_port);
385 if (udp_port < 0) 388 if (udp_port < 0)
386 goto out_free; 389 goto out_free;
387 port_array[cpu] = udp_port; 390 port_array[cpu] = udp_port;
388 pid_array[cpu] = pid; 391 pid_array[cpu] = pid;
392 /* due to some bugging finding ports, force search after last port */
393 start_port = udp_port+1;
389 } 394 }
390 395
391 /* send the client a comma deliminated set of port numbers */ 396 /* send the client a comma deliminated set of port numbers */