ia64/xen-unstable

changeset 16507:190c2592247d

xentrace: Don't append trace on existing file.

When you run "xentrace -e <mask> trace.output" the first time, all is
fine. When you run it a second time, then the data is appended which
makes you reading old data with xentrace_format and you interprete it
as new data. This usually happens when you automated tracing guests
with xentrace and xentrace_format with a script.

Therefore, attached patch makes xentrace to truncate the file to zero
bytes before writing any data.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Dec 04 10:17:32 2007 +0000 (2007-12-04)
parents 6e7cf648f7f3
children d2bef6551c12
files tools/xentrace/xentrace.c
line diff
     1.1 --- a/tools/xentrace/xentrace.c	Tue Dec 04 10:13:04 2007 +0000
     1.2 +++ b/tools/xentrace/xentrace.c	Tue Dec 04 10:17:32 2007 +0000
     1.3 @@ -572,24 +572,24 @@ int main(int argc, char **argv)
     1.4  
     1.5      parse_args(argc, argv);
     1.6      
     1.7 -    if (opts.evt_mask != 0) { 
     1.8 +    if ( opts.evt_mask != 0 )
     1.9          set_mask(opts.evt_mask, 0);
    1.10 -    }
    1.11  
    1.12 -    if (opts.cpu_mask != 0) {
    1.13 +    if ( opts.cpu_mask != 0 )
    1.14          set_mask(opts.cpu_mask, 1);
    1.15 -    }
    1.16  
    1.17      if ( opts.outfile )
    1.18 -        outfd = open(opts.outfile, O_WRONLY | O_CREAT | O_LARGEFILE, 0644);
    1.19 +        outfd = open(opts.outfile,
    1.20 +                     O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE,
    1.21 +                     0644);
    1.22  
    1.23 -    if(outfd < 0)
    1.24 +    if ( outfd < 0 )
    1.25      {
    1.26          perror("Could not open output file");
    1.27          exit(EXIT_FAILURE);
    1.28      }        
    1.29  
    1.30 -    if(isatty(outfd))
    1.31 +    if ( isatty(outfd) )
    1.32      {
    1.33          fprintf(stderr, "Cannot output to a TTY, specify a log file.\n");
    1.34          exit(EXIT_FAILURE);