From 1a92b6b3b88cd2b8a25cd0a90f9c98196fccca6c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 30 May 2020 21:58:20 +0200 Subject: Add -0 flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- sctrace.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sctrace.c b/sctrace.c index 4e0e37b..43afce7 100644 --- a/sctrace.c +++ b/sctrace.c @@ -8,7 +8,7 @@ char *argv0; static void usage(void) { - fprintf(stderr, "usage: %s [-o trace-output-file] [-f] command ...\n", argv0); + fprintf(stderr, "usage: %s [-o trace-output-file] [-f] (command | -0 command argv0) [argument] ...\n", argv0); exit(1); } @@ -91,16 +91,18 @@ main(int argc, char **argv) char *outfile = NULL; FILE *outfp = stderr; const char *num = NULL; - int status, exit_value = 0, trace_event; + int status, exit_value = 0, trace_event, with_argv0 = 0; unsigned long int trace_options = PTRACE_O_EXITKILL | PTRACE_O_TRACESYSGOOD; struct process *proc, *proc2; unsigned long int event; - /* TODO add support for exec */ + /* TODO add support for exec after vfork */ /* TODO add option to trace threads (-t) */ /* TODO add option to trace signals (-s) */ - /* TODO add option to specify argv[0] */ ARGBEGIN { + case '0': + with_argv0 = 1; + break; case 'o': if (outfile) usage(); @@ -130,7 +132,7 @@ main(int argc, char **argv) return 1; } /* exec will block until parent attaches */ - execvp(*argv, argv); + execvp(*argv, &argv[with_argv0]); eprintf("execvp %s:", *argv); default: orig_pid = pid; -- cgit v1.2.3-70-g09d2