perf tools: Fix probing for PERF_FLAG_FD_CLOEXEC flag
authorAdrian Hunter <adrian.hunter@intel.com>
Tue, 24 Feb 2015 11:20:59 +0000 (13:20 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 25 Feb 2015 19:40:13 +0000 (16:40 -0300)
commit48536c9195ae8c2a00fd8f400bac72ab613feaab
tree59621cfff58dca6939d0cb780e3857d416bad2b7
parent95a09cfa3cdf94231ce511f1697754482b918d39
perf tools: Fix probing for PERF_FLAG_FD_CLOEXEC flag

Commit f6edb53c4993ffe92ce521fb449d1c146cea6ec2 converted the probe to
a CPU wide event first (pid == -1). For kernels that do not support
the PERF_FLAG_FD_CLOEXEC flag the probe fails with EINVAL. Since this
errno is not handled pid is not reset to 0 and the subsequent use of
pid = -1 as an argument brings in an additional failure path if
perf_event_paranoid > 0:

$ perf record -- sleep 1
perf_event_open(..., 0) failed unexpectedly with error 13 (Permission denied)
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.007 MB /tmp/perf.data (11 samples) ]

Also, ensure the fd of the confirmation check is closed and comment why
pid = -1 is used.

Needs to go to 3.18 stable tree as well.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Based-on-patch-by: David Ahern <david.ahern@oracle.com>
Acked-by: David Ahern <david.ahern@oracle.com>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/54EC610C.8000403@intel.com
Cc: stable@vger.kernel.org # v3.18+
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/cloexec.c