From: Eugene Syromyatnikov Date: Wed, 28 Mar 2018 14:49:57 +0000 (+0200) Subject: strace.c: add support for opening output file in append mode X-Git-Tag: v4.22~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be55c1c61aec47062564f27aa9308f30d291c49b;p=strace strace.c: add support for opening output file in append mode * strace.c (open_append): New variable. (init): Handle -A option. (strace_fopen): Open file in "a" mode if open_append is set to true. * strace.1.in: Document this. * NEWS: Mention this. Suggested-by: Philipp Marek Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528488 --- diff --git a/NEWS b/NEWS index 171c657b..3d801f9f 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,8 @@ Noteworthy changes in release ?.?? (????-??-??) * Improvements * Implemented delay injection (-e inject=SET:delay_enter= and -e inject=SET:delay_exit= options). + * Added -A option for opening output files in append mode + (addresses Debian bug #528488). * IPv6 addresses shown in socket information in -yy mode are now printed in brackets. * Enhanced decoding of prctl and ptrace syscalls. diff --git a/strace.1.in b/strace.1.in index 3f47cbea..46a55e5e 100644 --- a/strace.1.in +++ b/strace.1.in @@ -58,7 +58,7 @@ strace \- trace system calls and signals .SH SYNOPSIS .SY strace -.OP \-CdffhikqrtttTvVxxy +.OP \-ACdffhikqrtttTvVxxy .OP \-I n .OP \-b execve .OM \-e expr @@ -274,6 +274,10 @@ without affecting the redirections of executed programs. The latter is not compatible with .B \-ff option currently. +.TP \-A +Open the file provided in the +.B \-o +option in append mode. .TP .B \-q Suppress messages about attaching, detaching etc. This happens diff --git a/strace.c b/strace.c index af2e9904..a76502af 100644 --- a/strace.c +++ b/strace.c @@ -150,6 +150,7 @@ static char *acolumn_spaces; static const char *outfname; /* If -ff, points to stderr. Else, it's our common output log */ static FILE *shared_log; +static bool open_append; struct tcb *printing_tcp; static struct tcb *current_tcp; @@ -449,7 +450,7 @@ strace_fopen(const char *path) FILE *fp; swap_uid(); - fp = fopen_stream(path, "w"); + fp = fopen_stream(path, open_append ? "a" : "w"); if (!fp) perror_msg_and_die("Can't fopen '%s'", path); swap_uid(); @@ -1594,13 +1595,16 @@ init(int argc, char *argv[]) #ifdef USE_LIBUNWIND "k" #endif - "a:b:cCdDe:E:fFhiI:o:O:p:P:qrs:S:tTu:vVwxyz")) != EOF) { + "a:Ab:cCdDe:E:fFhiI:o:O:p:P:qrs:S:tTu:vVwxyz")) != EOF) { switch (c) { case 'a': acolumn = string_to_uint(optarg); if (acolumn < 0) error_opt_arg(c, optarg); break; + case 'A': + open_append = true; + break; case 'b': if (strcmp(optarg, "execve") != 0) error_msg_and_die("Syscall '%s' for -b isn't supported",