diff --git a/defs.h b/defs.h index eb1713491e..1b9bb1e5a7 100644 --- a/defs.h +++ b/defs.h @@ -473,6 +473,7 @@ extern struct path_set { size_t size; } global_path_set; # define tracing_paths (global_path_set.num_selected != 0) +extern unsigned enable_wildcard_path_matching; extern unsigned xflag; extern unsigned followfork; # ifdef ENABLE_STACKTRACE diff --git a/pathtrace.c b/pathtrace.c index e3903b9d44..2d3b2548e7 100644 --- a/pathtrace.c +++ b/pathtrace.c @@ -10,17 +10,19 @@ #include "defs.h" #include #include +#include #include "syscall.h" #include "xstring.h" struct path_set global_path_set; +unsigned enable_wildcard_path_matching; /* * Return true if specified path matches one that we're tracing. */ static bool -pathmatch(const char *path, struct path_set *set) +pathmatch_exact(const char *path, struct path_set *set) { unsigned i; @@ -31,6 +33,33 @@ pathmatch(const char *path, struct path_set *set) return false; } +/* + * Return true if specified path matches one that we're tracing. + */ +static bool +pathmatch_wildcard(const char *path, struct path_set *set) +{ + unsigned i; + + for (i = 0; i < set->num_selected; ++i) { + if (fnmatch(set->paths_selected[i], path, 0) == 0) + return true; + } + return false; +} + +/* + * Return true if specified path matches one that we're tracing. + */ +static bool +pathmatch(const char *path, struct path_set *set) +{ + if (enable_wildcard_path_matching) + return pathmatch_wildcard(path, set); + else + return pathmatch_exact(path, set); +} + /* * Return true if specified path (in user-space) matches. */ diff --git a/strace.c b/strace.c index 86ca3c3569..e8154168e6 100644 --- a/strace.c +++ b/strace.c @@ -1650,7 +1650,7 @@ init(int argc, char *argv[]) #ifdef ENABLE_STACKTRACE "k" #endif - "a:Ab:cCdDe:E:fFhiI:o:O:p:P:qrs:S:tTu:vVwxX:yzZ"; + "a:Ab:cCdDe:E:fFhiI:o:O:p:P:qrs:S:tTu:vVwWxX:yzZ"; enum { SECCOMP_OPTION = 0x100 @@ -1772,6 +1772,9 @@ init(int argc, char *argv[]) case 'w': count_wallclock = 1; break; + case 'W': + enable_wildcard_path_matching = 1; + break; case 'x': xflag++; break;