[PATCH v7 6/8] Add path filter

Nikolay Marchuk marchuk.nikolay.a at gmail.com
Fri Aug 11 10:43:51 UTC 2017


* basic_filters.c: Add path filter functions.
* filter.c (filter_types): Add path filter entries.
* pathtrace.c (storepath): Duplicate path.
---
 basic_filters.c | 30 ++++++++++++++++++++++++++++++
 filter.c        |  2 ++
 pathtrace.c     |  2 +-
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/basic_filters.c b/basic_filters.c
index f12c9046..e20baa58 100644
--- a/basic_filters.c
+++ b/basic_filters.c
@@ -443,3 +443,33 @@ free_fd_filter(void *_priv_data)
 	free(set);
 	return;
 }
+
+void *
+parse_path_filter(const char *path, const char *const name)
+{
+	struct path_set *set = xcalloc(1, 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 *set = _priv_data;
+	unsigned int i;
+
+	for (i = 0; i < set->num_selected; ++i)
+		free((char *) set->paths_selected[i]);
+	free(set->paths_selected);
+	free(set);
+	return;
+}
diff --git a/filter.c b/filter.c
index d51b3183..03a54c3a 100644
--- a/filter.c
+++ b/filter.c
@@ -39,6 +39,7 @@ free_ ## name ## _filter(void *)					\
 
 DECL_FILTER(syscall);
 DECL_FILTER(fd);
+DECL_FILTER(path);
 #undef DECL_FILTER
 
 #define FILTER_TYPE(name)						\
@@ -54,6 +55,7 @@ static const struct filter_type {
 } filter_types[] = {
 	FILTER_TYPE(syscall),
 	FILTER_TYPE(fd),
+	FILTER_TYPE(path),
 };
 #undef FILTER_TYPE
 
diff --git a/pathtrace.c b/pathtrace.c
index f528c252..531ad8aa 100644
--- a/pathtrace.c
+++ b/pathtrace.c
@@ -93,7 +93,7 @@ storepath(const char *path, struct path_set *set)
 	set->paths_selected = xreallocarray(set->paths_selected,
 					    set->num_selected,
 					    sizeof(set->paths_selected[0]));
-	set->paths_selected[i] = path;
+	set->paths_selected[i] = xstrdup(path);
 }
 
 /*
-- 
2.11.0





More information about the Strace-devel mailing list