[RFC PATCH v11 2/8] perf data: Allow to use given fd in data->file.fd
From: weilin . wang
Date: Wed Jun 05 2024 - 01:22:35 EST
From: Weilin Wang <weilin.wang@xxxxxxxxx>
When in PIPE mode, allow to use fd dynamically opened and asigned to
data->file.fd instead of STDIN_FILENO or STDOUT_FILENO.
Signed-off-by: Weilin Wang <weilin.wang@xxxxxxxxx>
---
tools/perf/util/data.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 08c4bfbd817f..98661ede2a73 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -204,7 +204,12 @@ static bool check_pipe(struct perf_data *data)
data->file.fd = fd;
data->use_stdio = false;
}
- } else {
+
+ /*
+ * When is_pipe and data->file.fd is given, use given fd
+ * instead of STDIN_FILENO or STDOUT_FILENO
+ */
+ } else if (data->file.fd <= 0) {
data->file.fd = fd;
}
}
--
2.43.0