]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
eu-stacktrace WIP: default stdin/stdout ("-") for --input/--output
authorSerhei Makarov <serhei@serhei.io>
Wed, 3 May 2023 18:32:30 +0000 (14:32 -0400)
committerSerhei Makarov <serhei@serhei.io>
Wed, 3 May 2023 18:32:30 +0000 (14:32 -0400)
Updated example usage:
- mkfifo /tmp/test.fifo
- eu-stacktrace </tmp/test.fifo >output=test.syscap &
- sysprof-cli --use-fifo=/tmp/test.fifo test.syscap

README.eu-stacktrace
src/stacktrace.c

index 5a2320a78ea4ff8f9a6655a35402958dffe31ab6..eb7a5e0cb05f1aa3e8eed72a8c6b148f3ece8d8d 100644 (file)
@@ -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
index e09331f156f2159f41de8335e775c4be91ecaaa1..7f522bf3edc43a966d7792335e91709dabf97a99 100644 (file)
@@ -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);