
On Fri, Apr 20, 2018 at 05:56:38PM +0100, Daniel P. Berrangé wrote:
Rather than specialcasing handling of the '*' character, use fnmatch() to get normal shell wildcard syntax, as described in 'man glob(7)'.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virlog.c | 17 +++++++++++++++-- src/util/virlog.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/util/virlog.c b/src/util/virlog.c index 5262d613f6..1db10fcc71 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -40,6 +40,7 @@ #if HAVE_SYS_UN_H # include <sys/un.h> #endif +#include <fnmatch.h>
#include "virerror.h" #include "virlog.h" @@ -508,7 +509,9 @@ virLogSourceUpdate(virLogSourcePtr source) size_t i;
for (i = 0; i < virLogNbFilters; i++) { - if (strstr(source->name, virLogFilters[i]->match)) { + if ((virLogFilters[i]->flags & VIR_LOG_GLOB) ? + (fnmatch(virLogFilters[i]->match, source->name, 0) == 0) : + (strstr(source->name, virLogFilters[i]->match) != NULL)) {
After doing some perf tests I determined that while fnmatch is x14 slower than strstr, this is not worth the code complexity - always using fnmatch is invisible in real world perf tests. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|