lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZCtMkejMly5W534I@kernel.org>
Date:   Mon, 3 Apr 2023 19:00:49 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     Namhyung Kim <namhyung@...nel.org>
Cc:     Jiri Olsa <jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...nel.org>,
        LKML <linux-kernel@...r.kernel.org>,
        linux-perf-users@...r.kernel.org,
        Kan Liang <kan.liang@...ux.intel.com>,
        Leo Yan <leo.yan@...aro.org>
Subject: Re: [PATCH 1/9] perf list: Use relative path for tracepoint scan

Em Mon, Apr 03, 2023 at 06:59:10PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Mar 31, 2023 at 01:29:41PM -0700, Namhyung Kim escreveu:
> > Signed-off-by: Namhyung Kim <namhyung@...nel.org>
> > ---
> >  tools/perf/util/print-events.c | 26 ++++++++++++++++++++------
> >  1 file changed, 20 insertions(+), 6 deletions(-)
> 
> Add to add this to fix on Alma Linux 8, and scandirat isn't being found
> on musl libc (Alpine Linux), probably we'll need some scaffolding...

Some discussion about this for some other project:

https://gitlab.com/apparmor/apparmor/-/merge_requests/107
 
> - Arnaldo
> 
> 
> diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> index 26a7e017c9284c01..28aa0b9300253d0a 100644
> --- a/tools/perf/util/print-events.c
> +++ b/tools/perf/util/print-events.c
> @@ -6,6 +6,7 @@
>  #include <string.h>
>  #include <fcntl.h>
>  #include <sys/param.h>
> +#include <unistd.h>
>  
>  #include <api/fs/tracing_path.h>
>  #include <linux/stddef.h>
>  
> > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> > index 62e9ea7dcf40..26a7e017c928 100644
> > --- a/tools/perf/util/print-events.c
> > +++ b/tools/perf/util/print-events.c
> > @@ -4,6 +4,7 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >  #include <string.h>
> > +#include <fcntl.h>
> >  #include <sys/param.h>
> >  
> >  #include <api/fs/tracing_path.h>
> > @@ -59,12 +60,20 @@ static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] = {
> >  void print_tracepoint_events(const struct print_callbacks *print_cb, void *print_state)
> >  {
> >  	struct dirent **sys_namelist = NULL;
> > +	char *events_path = get_tracing_file("events");
> >  	int sys_items = tracing_events__scandir_alphasort(&sys_namelist);
> > +	int events_fd = open(events_path, O_PATH);
> > +
> > +	put_tracing_file(events_path);
> > +	if (events_fd < 0) {
> > +		printf("Error: failed to open tracing events directory\n");
> > +		return;
> > +	}
> >  
> >  	for (int i = 0; i < sys_items; i++) {
> >  		struct dirent *sys_dirent = sys_namelist[i];
> >  		struct dirent **evt_namelist = NULL;
> > -		char *dir_path;
> > +		int dir_fd;
> >  		int evt_items;
> >  
> >  		if (sys_dirent->d_type != DT_DIR ||
> > @@ -72,22 +81,26 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print
> >  		    !strcmp(sys_dirent->d_name, ".."))
> >  			continue;
> >  
> > -		dir_path = get_events_file(sys_dirent->d_name);
> > -		if (!dir_path)
> > +		dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH);
> > +		if (dir_fd < 0)
> >  			continue;
> >  
> > -		evt_items = scandir(dir_path, &evt_namelist, NULL, alphasort);
> > +		evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort);
> >  		for (int j = 0; j < evt_items; j++) {
> >  			struct dirent *evt_dirent = evt_namelist[j];
> >  			char evt_path[MAXPATHLEN];
> > +			int evt_fd;
> >  
> >  			if (evt_dirent->d_type != DT_DIR ||
> >  			    !strcmp(evt_dirent->d_name, ".") ||
> >  			    !strcmp(evt_dirent->d_name, ".."))
> >  				continue;
> >  
> > -			if (tp_event_has_id(dir_path, evt_dirent) != 0)
> > +			snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name);
> > +			evt_fd = openat(dir_fd, evt_path, O_RDONLY);
> > +			if (evt_fd < 0)
> >  				continue;
> > +			close(evt_fd);
> >  
> >  			snprintf(evt_path, MAXPATHLEN, "%s:%s",
> >  				 sys_dirent->d_name, evt_dirent->d_name);
> > @@ -103,10 +116,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print
> >  					/*long_desc=*/NULL,
> >  					/*encoding_desc=*/NULL);
> >  		}
> > -		free(dir_path);
> > +		close(dir_fd);
> >  		free(evt_namelist);
> >  	}
> >  	free(sys_namelist);
> > +	close(events_fd);
> >  }
> >  
> >  void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> > -- 
> > 2.40.0.348.gf938b09366-goog
> > 
> 
> -- 
> 
> - Arnaldo

-- 

- Arnaldo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ