aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2020-05-30 21:58:20 +0200
committerMattias Andrée <maandree@kth.se>2020-05-30 21:58:20 +0200
commit1a92b6b3b88cd2b8a25cd0a90f9c98196fccca6c (patch)
tree251e9c6d35df8072c03f6f0ddbcec11e8a8afbdf
parentm + add support for tracing vfork children (diff)
downloadsctrace-1a92b6b3b88cd2b8a25cd0a90f9c98196fccca6c.tar.gz
sctrace-1a92b6b3b88cd2b8a25cd0a90f9c98196fccca6c.tar.bz2
sctrace-1a92b6b3b88cd2b8a25cd0a90f9c98196fccca6c.tar.xz
Add -0 flag
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--sctrace.c12
1 files 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;