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]
Date:	Tue, 04 Sep 2012 10:09:56 +0900
From:	Namhyung Kim <namhyung@...nel.org>
To:	Feng Tang <feng.tang@...el.com>
Cc:	acme@...hat.com, mingo@...e.hu, a.p.zijlstra@...llo.nl,
	andi@...stfloor.org, dsahern@...il.com,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/7] perf scripts: Export a find_scripts() function

On Mon,  3 Sep 2012 16:14:30 +0800, Feng Tang wrote:
> So that other perf commands/browser has a way to dig out the available
> scripts info in system, this is a preparation for the script browser.
>
> Signed-off-by: Feng Tang <feng.tang@...el.com>
> ---
>  tools/perf/builtin-script.c |   46 +++++++++++++++++++++++++++++++++++++++++++
>  tools/perf/builtin.h        |    1 +
>  2 files changed, 47 insertions(+), 0 deletions(-)
>
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 7ab86bb..d46056c 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -1031,6 +1031,52 @@ static int list_available_scripts(const struct option *opt __used,
>  	exit(0);
>  }
>  
> +/*
> + * Return 0 if none is found, otherwise the actual scripts number.
> + *
> + * Currently we just return all the raw scripts name, and their full path.
> + *
> + */
> +int find_scripts(char **scripts_array, char **scripts_path_array)
> +{
> +	struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
> +	char scripts_path[MAXPATHLEN];
> +	DIR *scripts_dir, *lang_dir;
> +	char lang_path[MAXPATHLEN];
> +	struct script_desc *desc;
> +	char first_half[BUFSIZ];
> +	char *temp;
> +	int i = 0;
> +
> +	first_half[0] = 0;
> +	desc = NULL;
> +
> +	snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
> +
> +	scripts_dir = opendir(scripts_path);
> +	if (!scripts_dir)
> +		return -1;
> +
> +	for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {

It'd be better if checking language supported - ie. by NO_LIBPERL and/or
NO_LIBPYTHON macro rather than showing all regardless.  Also you might
consider when perf was built with no script language support.

Thanks,
Namhyung


> +		snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
> +			 lang_dirent.d_name);
> +		lang_dir = opendir(lang_path);
> +		if (!lang_dir)
> +			continue;
> +
> +		for_each_script(lang_path, lang_dir, script_dirent, script_next) {
> +			sprintf(scripts_path_array[i], "%s/%s", lang_path,
> +				script_dirent.d_name);
> +			temp = strchr(script_dirent.d_name, '.');
> +			snprintf(scripts_array[i], (temp - script_dirent.d_name) + 1,
> +				"%s", script_dirent.d_name);
> +			i++;
> +		}
> +	}
> +
> +	return i;
> +}
> +
>  static char *get_script_path(const char *script_root, const char *suffix)
>  {
>  	struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
> diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
> index b382bd5..3ea74ed 100644
> --- a/tools/perf/builtin.h
> +++ b/tools/perf/builtin.h
> @@ -36,4 +36,5 @@ extern int cmd_kvm(int argc, const char **argv, const char *prefix);
>  extern int cmd_test(int argc, const char **argv, const char *prefix);
>  extern int cmd_inject(int argc, const char **argv, const char *prefix);
>  
> +extern int find_scripts(char **scripts_array, char **scripts_path_array);
>  #endif
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ