]> granicus.if.org Git - strace/commitdiff
strace.c: add support for opening output file in append mode
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 28 Mar 2018 14:49:57 +0000 (16:49 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 4 Apr 2018 20:32:42 +0000 (20:32 +0000)
* 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
NEWS
strace.1.in
strace.c

diff --git a/NEWS b/NEWS
index 171c657b28b13377a6c232af921f84e959753bb1..3d801f9f05b76606997c09a423aa5f89b49add99 100644 (file)
--- 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.
index 3f47cbea8e5117ebf4292689e87fec8a870b9a5e..46a55e5e6511e7137ea9c8d4efef0d2828261298 100644 (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
index af2e99045b7b3d2e1c1b9338013fd7239e59070e..a76502af989b212cf926c0941ae5b22741a7c8d2 100644 (file)
--- 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",