[libvirt] [PATCH 3/4] log: support logging using shell wildcard syntax
Daniel P. Berrangé
berrange at redhat.com
Mon Apr 23 12:29:54 UTC 2018
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 at 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 :|
More information about the libvir-list
mailing list