From: Roland McGrath Date: Fri, 7 Nov 2003 02:26:54 +0000 (+0000) Subject: 2003-11-06 Roland McGrath X-Git-Tag: v4.5.18~677 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=37b9a66dd4cf063c4a3d1002f4196cd7ef9ae5b7;p=strace 2003-11-06 Roland McGrath * strace.c (main): Treat piped output more like file output. Disallow -ff with piped output. Fixes RH#105366. Reported by Dmitry V. Levin --- diff --git a/strace.c b/strace.c index 02d1e6e8..1d057fcd 100644 --- 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 .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; }