[PATCH] perf stat: fix output selection introduced in 56f3bae7

From: Åukasz Stelmach
Date: Thu Apr 19 2012 - 04:13:48 EST


56f3bae7 makes perf require either --output or --log-fd. Without them
perf exited after erroneously trying to open stdout (file descriptor 0
by default) for writing.

Signed-off-by: Åuaksz Stelmach <l.stelmach@xxxxxxxxxxx>
Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx>
---
tools/perf/builtin-stat.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c941bb6..c0f8129 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -196,7 +196,7 @@ static bool csv_output = false;
static bool group = false;
static const char *output_name = NULL;
static FILE *output = NULL;
-static int output_fd;
+static int output_fd = -1;

static volatile int done = 0;

@@ -1146,7 +1146,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
if (output_name && strcmp(output_name, "-"))
output = NULL;

- if (output_name && output_fd) {
+ if (output_name && output_fd >= 0) {
fprintf(stderr, "cannot use both --output and --log-fd\n");
usage_with_options(stat_usage, options);
}
@@ -1161,7 +1161,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
}
clock_gettime(CLOCK_REALTIME, &tm);
fprintf(output, "# started on %s\n", ctime(&tm.tv_sec));
- } else if (output_fd != 2) {
+ } else if (output_fd >= 0) {
mode = append_file ? "a" : "w";
output = fdopen(output_fd, mode);
if (!output) {
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/