aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-03-31 06:01:43 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-03-31 06:03:30 -0400
commitd9b58d42c43c2c52a68fe368105d821607fab855 (patch)
tree2f8264e7e67f7c08e8b54b2d8fa21d1aceb78579
parent75ffcee53dc3dc8b2d2258ce2bdcee0c5c834d7f (diff)
trace-cmd: Fix temp files in trace-cmd split to include directories
If a directory is specified in the output file for trace-cmd split, then it would fault because of the adding of the prefix ".tmp" to the output name. This patch fixes the issues by parsing out the directory name and basename from the output path. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-split.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/trace-split.c b/trace-split.c
index 9840d62..489e6cf 100644
--- a/trace-split.c
+++ b/trace-split.c
@@ -24,6 +24,7 @@
24#include <stdio.h> 24#include <stdio.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <string.h> 26#include <string.h>
27#include <libgen.h>
27#include <getopt.h> 28#include <getopt.h>
28#include <stdarg.h> 29#include <stdarg.h>
29#include <sys/types.h> 30#include <sys/types.h>
@@ -333,11 +334,18 @@ static double parse_file(struct tracecmd_input *handle,
333 struct cpu_data *cpu_data; 334 struct cpu_data *cpu_data;
334 struct record *record; 335 struct record *record;
335 char **cpu_list; 336 char **cpu_list;
337 char *output;
338 char *base;
336 char *file; 339 char *file;
340 char *dir;
337 int cpus; 341 int cpus;
338 int cpu; 342 int cpu;
339 int fd; 343 int fd;
340 344
345 output = strdup(output_file);
346 dir = dirname(output);
347 base = basename(output);
348
341 ohandle = tracecmd_copy(handle, output_file); 349 ohandle = tracecmd_copy(handle, output_file);
342 350
343 cpus = tracecmd_cpus(handle); 351 cpus = tracecmd_cpus(handle);
@@ -345,7 +353,7 @@ static double parse_file(struct tracecmd_input *handle,
345 353
346 for (cpu = 0; cpu < cpus; cpu++) { 354 for (cpu = 0; cpu < cpus; cpu++) {
347 file = malloc_or_die(strlen(output_file) + 50); 355 file = malloc_or_die(strlen(output_file) + 50);
348 sprintf(file, ".tmp.%s.%d", output_file, cpu); 356 sprintf(file, "%s/.tmp.%s.%d", dir, base, cpu);
349 fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); 357 fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644);
350 cpu_data[cpu].cpu = cpu; 358 cpu_data[cpu].cpu = cpu;
351 cpu_data[cpu].fd = fd; 359 cpu_data[cpu].fd = fd;
@@ -383,6 +391,7 @@ static double parse_file(struct tracecmd_input *handle,
383 } 391 }
384 free(cpu_data); 392 free(cpu_data);
385 free(cpu_list); 393 free(cpu_list);
394 free(output);
386 tracecmd_output_close(ohandle); 395 tracecmd_output_close(ohandle);
387 396
388 return current; 397 return current;