[PATCH v5 7/8] Add path filter

Eugene Syromiatnikov esyr at redhat.com
Mon Jul 24 15:54:26 UTC 2017


On Wed, Jul 19, 2017 at 05:26:50PM +0700, Nikolay Marchuk wrote:
> * basic_filters.c: Add path filter functions.
> * filter.c (filter_types): Add path filter entries.
> ---
>  basic_filters.c | 34 ++++++++++++++++++++++++++++++++++
>  filter.c        |  4 +++-
>  2 files changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/basic_filters.c b/basic_filters.c
> index ca4f78c..5663ed9 100644
> --- a/basic_filters.c
> +++ b/basic_filters.c
> @@ -473,3 +473,37 @@ free_fd_filter(void *_priv_data)
>  	free(set);
>  	return;
>  }
> +
> +/* Additional path_set struct, necessary to free the filter. */
> +struct path_set_filter {
> +	char **paths_selected;
> +	unsigned int num_selected;
> +};
Why this when you have struct path_set already? Moreover, you return
struct path_set and not struct path_set_filter in parse_path_filter.

> +
> +void *
> +parse_path_filter(const char *path, const char *const name)
> +{
> +	struct path_set *set = xmalloc(sizeof(struct path_set));
Missing empty line after declaration.

> +	memset(set, 0, sizeof(struct path_set));
> +	pathtrace_select_set(path, set);
> +	return set;
> +}
> +
> +bool
> +run_path_filter(struct tcb *tcp, void *_priv_data)
> +{
> +	struct path_set *set = _priv_data;
Missing empty line after declaration.

> +	return pathtrace_match_set(tcp, set);
> +}
> +
> +void
> +free_path_filter(void *_priv_data)
> +{
> +	struct path_set_filter *set = _priv_data;
> +	unsigned int i;
Missing empty line after declarations.

> +	for (i = 0; i < set->num_selected; ++i)
> +		free(set->paths_selected[i]);
> +	free(set->paths_selected);
> +	free(set);
> +	return;
> +}
> diff --git a/filter.c b/filter.c
> index 934b0eb..5582d2a 100644
> --- a/filter.c
> +++ b/filter.c
> @@ -36,6 +36,7 @@ extern void								\
>  free_ ## name ## _filter(void *)
>  DECL_FILTER(syscall);
>  DECL_FILTER(fd);
> +DECL_FILTER(path);
>  #undef DECL_FILTER
>  
>  #define FILTER_TYPE(name)						\
> @@ -49,7 +50,8 @@ static const struct filter_type {
>  	void (*free_priv_data)(void *);
>  } filter_types[] = {
>  	FILTER_TYPE(syscall),
> -	FILTER_TYPE(fd)
> +	FILTER_TYPE(fd),
> +	FILTER_TYPE(path)
It's preferable to have trailing commas here, as it leads to cleaner
patches.

>  };
>  
>  #undef FILTER_TYPE
> -- 
> 2.1.4




More information about the Strace-devel mailing list