[ I just realized I already pushed your patch. Here's an update to what I would like. ] From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx> Instead of forking a command specified on the command line and returning right away, have it wait for the process to finish before returning. Unless "--fork" is specified as well. Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> --- Documentation/trace-cmd-start.1.txt | 7 +++++++ tracecmd/trace-record.c | 18 +++++++++++++----- tracecmd/trace-usage.c | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Documentation/trace-cmd-start.1.txt b/Documentation/trace-cmd-start.1.txt index 63d2034c..07f2ed3a 100644 --- a/Documentation/trace-cmd-start.1.txt +++ b/Documentation/trace-cmd-start.1.txt @@ -23,6 +23,13 @@ OPTIONS The options are the same as 'trace-cmd-record(1)', except that it does not take options specific to recording (*-s*, *-o*, *-N*, and *-t*). +*--fork* :: + This option is only available for trace-cmd start. It tells trace-cmd + to not wait for the process to finish before returning. + With this option, trace-cmd start will return right after it forks + the process on the command line. This option only has an effect if + trace-cmd start also executes a command. + SEE ALSO -------- trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-stop(1), diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 4d2039a1..143b736e 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -86,6 +86,8 @@ static char *host; static bool quiet; +static bool fork_process; + /* Max size to let a per cpu file get */ static int max_kb; @@ -1604,7 +1606,7 @@ static void run_cmd(enum trace_type type, const char *user, int argc, char **arg /* child */ update_task_filter(); tracecmd_enable_tracing(); - if (type != TRACE_TYPE_START) + if (!fork_process) enable_ptrace(); /* * If we are using stderr for stdout, switch @@ -1626,13 +1628,15 @@ static void run_cmd(enum trace_type type, const char *user, int argc, char **arg die("Failed to exec %s", argv[0]); } } - if (type & TRACE_TYPE_START) + if (fork_process) exit(0); if (do_ptrace) { ptrace_attach(NULL, pid); ptrace_wait(type); } else trace_waitpid(type, pid, &status, 0); + if (type & TRACE_TYPE_START) + exit(0); } static void @@ -5535,6 +5539,7 @@ void init_top_instance(void) } enum { + OPT_fork = 241, OPT_tsyncinterval = 242, OPT_user = 243, OPT_procmap = 244, @@ -5851,6 +5856,7 @@ static void parse_record_options(int argc, {"user", required_argument, NULL, OPT_user}, {"module", required_argument, NULL, OPT_module}, {"tsync-interval", required_argument, NULL, OPT_tsyncinterval}, + {"fork", no_argument, NULL, OPT_fork}, {NULL, 0, NULL, 0} }; @@ -6204,6 +6210,11 @@ static void parse_record_options(int argc, top_instance.tsync.loop_interval = atoi(optarg); guest_sync_set = true; break; + case OPT_fork: + if (!IS_START(ctx)) + die("--fork option used for 'start' command only"); + fork_process = true; + break; case OPT_quiet: case 'q': quiet = true; @@ -6266,9 +6277,6 @@ static void parse_record_options(int argc, } } - if (do_ptrace && IS_START(ctx)) - die("ptrace not supported with command start"); - for_all_instances(instance) { if (instance->get_procmap && !instance->nr_filter_pids) { warning("--proc-map is ignored for instance %s, " diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c index 58bca9e4..1e832be8 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -71,6 +71,8 @@ static struct usage_help usage_help[] = { " %s start [-e event][-p plugin][-d][-O option ][-P pid]\n" " Uses same options as record.\n" " It only enables the tracing and exits\n" + "\n" + " --fork: If a command is specified, then return right after it forks\n" }, { "extract", -- 2.25.4