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 <philipp.marek@emerion.com>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528488
This commit is contained in:
Eugene Syromyatnikov 2018-03-28 16:49:57 +02:00 committed by Dmitry V. Levin
parent 698e9c30d4
commit be55c1c61a
3 changed files with 13 additions and 3 deletions

2
NEWS
View File

@ -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.

View File

@ -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

View File

@ -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",