[PATCH] Introduce new filtering architecture
Dmitry V. Levin
ldv at altlinux.org
Tue Jun 20 01:42:56 UTC 2017
On Mon, Jun 19, 2017 at 08:37:32PM +0700, Nikolay Marchuk wrote:
> On 19.06.2017 11:08, Eugene Syromiatnikov wrote:
> >> + if (!strncmp(name, str, len)) {
> > Not sure whether strncmp is better than strcmp here, since this function
> > is not called with user-supplied str at all.
> >
> > Or, do you expect that these will work with user-supplied strings in the
> > future?
> >
> > BTW, personally, I don't think that this needs to be string-keyed.
> > Something as simple as
> >
> > enum filter_type_name {
> > FILTER_TYPE_syscall,
> > FILTER_TYPE_fd,
> > };
> >
> > #define FILTER_TYPE(name) \
> > [FILTER_TYPE_ ## name] = { \
> > .parse_filter = parse_ ## name ## _filter, \
> > .run_filter = run_ ## name ## _filter, \
> > ._free_priv_data = free_ ## name ## _filter, \
> > }
> >
> > static const struct filter_type {
> > void* (*parse_filter)(const char *, const char *const);
> > bool (*run_filter)(struct tcb *, void *);
> > void (*_free_priv_data)(void *);
> > } filter_types[] = {
> > FILTER_TYPE(syscall),
> > FILTER_TYPE(fd),
> > };
> >
> > struct filter *
> > add_filter_to_array(struct filter **filters, unsigned int *nfilters,
> > enum filter_type_name name)
> > {
> > *filters = xreallocarray(*filters, ++(*nfilters),
> > sizeof(struct filter));
> > struct filter *filter = &((*filters)[*nfilters - 1]);
> > filter->type = filters[name];
> > return filter;
> > }
> >
> > [...]
> >
> > #define create_filter(a, t) actual_create_filter(a, FILTER_TYPE_ ## t)
> >
> > [...]
> >
> > create_filter(action, fd);
> >
> > should also suffice.
> I am going to use string-keyed filters and actions for new filtering
> language parsing and enum is not sufficient.
I'm not sure I follow this; how could it be that enum is not sufficient?
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170620/177b6f08/attachment.bin>
More information about the Strace-devel
mailing list