[PATCH v4 6/6] Add path filter

Nikolay Marchuk marchuk.nikolay.a at gmail.com
Fri Jul 14 14:55:35 UTC 2017


* basic_actions.c (apply_trace): Move global path tracing to trace action.
* syscall.c (syscall_entering_trace): Likewise.
* basic_filters.c: Add path filter functions.
* filter.c (filter_types): Add path filter entry.
---
 basic_actions.c |  3 ++-
 basic_filters.c | 33 +++++++++++++++++++++++++++++++++
 filter.c        |  4 +++-
 syscall.c       |  3 +--
 4 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/basic_actions.c b/basic_actions.c
index ae65059..144a3d6 100644
--- a/basic_actions.c
+++ b/basic_actions.c
@@ -54,7 +54,8 @@ free_null(void *_priv_data)
 void
 apply_trace(struct tcb *tcp, void *_priv_data)
 {
-	tcp->qual_flg |= QUAL_TRACE;
+	if (!tracing_paths || pathtrace_match(tcp))
+		tcp->qual_flg |= QUAL_TRACE;
 }
 
 void
diff --git a/basic_filters.c b/basic_filters.c
index 577eb02..d178631 100644
--- a/basic_filters.c
+++ b/basic_filters.c
@@ -469,3 +469,36 @@ free_fd_filter(void *_priv_data)
 	free(set);
 	return;
 }
+
+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);
+}
+
+struct path_set_can_free {
+	char **paths_selected;
+	unsigned int num_selected;
+};
+
+void
+free_path_filter(void *_priv_data)
+{
+	struct path_set_can_free *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 05382b7..283ee01 100644
--- a/filter.c
+++ b/filter.c
@@ -37,6 +37,7 @@ extern void								\
 free_ ## name ## _filter(void *)
 DECL_FILTER(syscall);
 DECL_FILTER(fd);
+DECL_FILTER(path);
 #undef DECL_FILTER
 
 #define FILTER_TYPE(name)						\
@@ -50,7 +51,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
diff --git a/syscall.c b/syscall.c
index 07157f1..3c906cf 100644
--- a/syscall.c
+++ b/syscall.c
@@ -704,8 +704,6 @@ syscall_entering_trace(struct tcb *tcp, unsigned int *sig)
 			break;
 	}
 
-	if (!(tcp->qual_flg & QUAL_TRACE)
-	 || (tracing_paths && !pathtrace_match(tcp))
-	) {
+	if (!(tcp->qual_flg & QUAL_TRACE)) {
 		tcp->flags |= TCB_FILTERED;
 		return 0;
}
-- 
2.1.4





More information about the Strace-devel mailing list