]> granicus.if.org Git - strace/commitdiff
2003-11-06 Roland McGrath <roland@redhat.com>
authorRoland McGrath <roland@redhat.com>
Fri, 7 Nov 2003 02:26:54 +0000 (02:26 +0000)
committerRoland McGrath <roland@redhat.com>
Fri, 7 Nov 2003 02:26:54 +0000 (02:26 +0000)
* strace.c (main): Treat piped output more like file output.
Disallow -ff with piped output.  Fixes RH#105366.
Reported by Dmitry V. Levin <ldv@altlinux.org>

strace.c

index 02d1e6e8b9cca7d3d85a70af5864dd111fb2402f..1d057fcd6201c869b2ad74016e977af363560de5 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -331,22 +331,31 @@ char *argv[];
        setreuid(geteuid(), getuid());
 #endif
 
-       /* See if they want to pipe the output. */
-       if (outfname && (outfname[0] == '|' || outfname[0] == '!')) {
-               if ((outf = popen(outfname + 1, "w")) == NULL) {
-                       fprintf(stderr, "%s: can't popen '%s': %s\n",
-                               progname, outfname + 1, strerror(errno));
-                       exit(1);
-               }
-               free(outfname);
-               outfname = NULL;
-       }
-
        /* Check if they want to redirect the output. */
        if (outfname) {
                long f;
 
-               if ((outf = fopen(outfname, "w")) == NULL) {
+               /* See if they want to pipe the output. */
+               if (outfname[0] == '|' || outfname[0] == '!') {
+                       /*
+                        * We can't do the <outfname>.PID funny business
+                        * when using popen, so prohibit it.
+                        */
+                       if (followfork > 1) {
+                               fprintf(stderr, "\
+%s: piping the output and -ff are mutually exclusive options\n",
+                                       progname);
+                               exit(1);
+                       }
+
+                       if ((outf = popen(outfname + 1, "w")) == NULL) {
+                               fprintf(stderr, "%s: can't popen '%s': %s\n",
+                                       progname, outfname + 1,
+                                       strerror(errno));
+                               exit(1);
+                       }
+               }
+               else if ((outf = fopen(outfname, "w")) == NULL) {
                        fprintf(stderr, "%s: can't fopen '%s': %s\n",
                                progname, outfname, strerror(errno));
                        exit(1);
@@ -367,10 +376,9 @@ char *argv[];
        setreuid(geteuid(), getuid());
 #endif
 
-       if (!outfname) {
+       if (!outfname || outfname[0] == '|' || outfname[0] == '!')
                setvbuf(outf, buf, _IOLBF, BUFSIZ);
-       }
-       else if (optind < argc) {
+       if (outfname && optind < argc) {
                interactive = 0;
                qflag = 1;
        }