[PATCH v5 7/8] Add path filter

Nikolay Marchuk marchuk.nikolay.a at gmail.com
Wed Jul 19 10:26:50 UTC 2017


* 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;
+};
+
+void *
+parse_path_filter(const char *path, const char *const name)
+{
+	struct path_set *set = xmalloc(sizeof(struct path_set));
+	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;
+	return pathtrace_match_set(tcp, set);
+}
+
+void
+free_path_filter(void *_priv_data)
+{
+	struct path_set_filter *set = _priv_data;
+	unsigned int i;
+	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)
 };
 
 #undef FILTER_TYPE
-- 
2.1.4





More information about the Strace-devel mailing list