Em Mon, Aug 12, 2019 at 05:22:51PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Aug 07, 2019 at 10:44:17AM -0400, Igor Lubashev escreveu:
> > Kernel requires CAP_SYS_ADMIN instead of euid==0 to mount debugfs for 
> > ftrace.
> > Make perf do the same.
> > 
> > Signed-off-by: Igor Lubashev <[email protected]>
> > ---
> >  tools/perf/builtin-ftrace.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
> > index ae1466aa3b26..d09eac8a6d57 100644
> > --- a/tools/perf/builtin-ftrace.c
> > +++ b/tools/perf/builtin-ftrace.c
> > @@ -13,6 +13,7 @@
> >  #include <signal.h>
> >  #include <fcntl.h>
> >  #include <poll.h>
> > +#include <linux/capability.h>
> >  
> >  #include "debug.h"
> >  #include <subcmd/parse-options.h>
> > @@ -21,6 +22,7 @@
> >  #include "target.h"
> >  #include "cpumap.h"
> >  #include "thread_map.h"
> > +#include "util/cap.h"
> >  #include "util/config.h"
> >  
> >  
> > @@ -281,7 +283,7 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int 
> > argc, const char **argv)
> >             .events = POLLIN,
> >     };
> >  
> > -   if (geteuid() != 0) {
> > +   if (!perf_cap__capable(CAP_SYS_ADMIN)) {
> >             pr_err("ftrace only works for root!\n");
> 
> I guess we should update the error message too? 
> 

I.e. I applied this as a follow up patch:

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 01a5bb58eb04..ba8b65c2f9dc 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -284,7 +284,12 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int 
argc, const char **argv)
        };
 
        if (!perf_cap__capable(CAP_SYS_ADMIN)) {
-               pr_err("ftrace only works for root!\n");
+               pr_err("ftrace only works for %s!\n",
+#ifdef HAVE_LIBCAP_SUPPORT
+               "users with the SYS_ADMIN capability"
+#else
+               "root"
+#endif
                return -1;
        }
 

Reply via email to