perf evlist: Don't run workload if not told to

The perf_evlist__prepare_workload() method works by forking and then
waiting on a fd that must be written to to allow the workload to be
exec()ed.

But if the tool calling it fails to, say, set up the events with which
it wants to sample the workload for, it will not call
perf_evlist__start_workload(), but even in this case the workload ended
up running:

  [acme@zoo linux]$ trace /bin/echo workload ends up running, it should not...
  Couldn't mmap the events: Operation not permitted
  workload ends up running, it should not...
  [acme@zoo linux]$

So check if at least one byte was written before letting exec() be
called.

Now the expected behaviour:

  [acme@zoo linux]$ trace /bin/echo workload ends up running, it should not...
  Couldn't mmap the events: Operation not permitted
  [acme@zoo linux]$
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-oh1ixo8m74rf295a05gfjw8b@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7d885749
...@@ -1061,6 +1061,8 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar ...@@ -1061,6 +1061,8 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar
} }
if (!evlist->workload.pid) { if (!evlist->workload.pid) {
int ret;
if (pipe_output) if (pipe_output)
dup2(2, 1); dup2(2, 1);
...@@ -1078,8 +1080,22 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar ...@@ -1078,8 +1080,22 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar
/* /*
* Wait until the parent tells us to go. * Wait until the parent tells us to go.
*/ */
if (read(go_pipe[0], &bf, 1) == -1) ret = read(go_pipe[0], &bf, 1);
perror("unable to read pipe"); /*
* The parent will ask for the execvp() to be performed by
* writing exactly one byte, in workload.cork_fd, usually via
* perf_evlist__start_workload().
*
* For cancelling the workload without actuallin running it,
* the parent will just close workload.cork_fd, without writing
* anything, i.e. read will return zero and we just exit()
* here.
*/
if (ret != 1) {
if (ret == -1)
perror("unable to read pipe");
exit(ret);
}
execvp(argv[0], (char **)argv); execvp(argv[0], (char **)argv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment