summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhei Makarov <serhei@serhei.io>2023-05-03 14:32:30 -0400
committerSerhei Makarov <serhei@serhei.io>2023-05-03 14:32:30 -0400
commit044eb0db7a4795d7a752c2174898379b9fdf43bf (patch)
tree4199ab36a5cb208b793a509586c273cee9e33caa
parentae918e26469a8756311ea558790311f240c26831 (diff)
downloadelfutils-044eb0db7a4795d7a752c2174898379b9fdf43bf.tar.gz
eu-stacktrace WIP: default stdin/stdout ("-") for --input/--output
Updated example usage: - mkfifo /tmp/test.fifo - eu-stacktrace </tmp/test.fifo >output=test.syscap & - sysprof-cli --use-fifo=/tmp/test.fifo test.syscap
-rw-r--r--README.eu-stacktrace5
-rw-r--r--src/stacktrace.c15
2 files changed, 12 insertions, 8 deletions
diff --git a/README.eu-stacktrace b/README.eu-stacktrace
index 5a2320a7..eb7a5e0c 100644
--- a/README.eu-stacktrace
+++ b/README.eu-stacktrace
@@ -34,14 +34,13 @@ Requirements:
Invoking `eu-stacktrace`:
- mkfifo /tmp/test.fifo
-- eu-stacktrace --input=/tmp/test.fifo --output=test.syscap &
+- eu-stacktrace </tmp/test.fifo >output=test.syscap &
- sysprof-cli --use-fifo=/tmp/test.fifo test.syscap
## TODO
-- support taking an FD for fork/exec pipes; then sysprof can fork eu-stacktrace
-- default to stdin/stdout for --input and --output
- initial version of packet parsing for sysprof
+- sysprof should fork eu-stacktrace and pipe info via stdin/stdout
- implement --mode=none
- implement --mode=naive
- implement --mode=caching
diff --git a/src/stacktrace.c b/src/stacktrace.c
index e09331f1..7f522bf3 100644
--- a/src/stacktrace.c
+++ b/src/stacktrace.c
@@ -103,10 +103,10 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
case ARGP_KEY_END:
if (input_path == NULL)
- argp_error (state, N_("-i PATH needs an input file or FIFO."));
+ input_path = "-"; /* default to stdin */
if (output_path == NULL)
- argp_error (state, N_("-o PATH needs an output path or FIFO."));
+ output_path = "-"; /* default to stdout */
if (processing_mode == 0)
processing_mode = MODE_PASSTHRU;
@@ -165,11 +165,16 @@ Utility is a work-in-progress, see README.eu-stacktrace in the source branch.")
#endif
/* TODO Also handle common expansions e.g. ~/foo instead of /home/user/foo. */
- /* TODO Also handle '-' path for stdin/stdout. */
- input_fd = open (input_path, O_RDONLY);
+ if (strcmp (input_path, "-") == 0)
+ input_fd = STDIN_FILENO;
+ else
+ input_fd = open (input_path, O_RDONLY);
if (input_fd < 0)
error (EXIT_BAD, errno, N_("Cannot open input file or FIFO '%s'"), input_path);
- output_fd = open (output_path, O_WRONLY);
+ if (strcmp (output_path, "-") == 0)
+ output_fd = STDOUT_FILENO;
+ else
+ output_fd = open (output_path, O_WRONLY);
if (output_fd < 0)
error (EXIT_BAD, errno, N_("Cannot open output file or FIFO '%s'"), output_path);