From: Serhei Makarov Date: Wed, 3 May 2023 18:32:30 +0000 (-0400) Subject: eu-stacktrace WIP: default stdin/stdout ("-") for --input/--output X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=044eb0db7a4795d7a752c2174898379b9fdf43bf;p=thirdparty%2Felfutils.git eu-stacktrace WIP: default stdin/stdout ("-") for --input/--output Updated example usage: - mkfifo /tmp/test.fifo - eu-stacktrace output=test.syscap & - sysprof-cli --use-fifo=/tmp/test.fifo test.syscap --- diff --git a/README.eu-stacktrace b/README.eu-stacktrace index 5a2320a78..eb7a5e0cb 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 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 e09331f15..7f522bf3e 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);