Re: [PATCH] libtracefs: An API to set the filtering of functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi steve,

i have one doubt.
>Note, @filters should be of type: const char * const * filters,  as not
>only is filters pointing to constant strings, the array itself will not be
>modified.

what If the user wants to capture the filters at run time like below ?
let's say

  filters = malloc(sizeof(char *));
        if (!filters)
                return 1;
        printf("please enter the input filters count\n");
        scanf("%d", &fil_count);
        while(i < fil_count) {
                scanf("%s", buf);
                slen = strlen(buf);
                if (!slen)
                        return 1;
                filters[i] = calloc(1, slen);
                strncpy(filters[i++], buf, slen);
        }
at that time, this declaration will be problematic right?, because we
are trying to modify
the read-only memory. Are we expecting the user to supply filters at
compile time like below?
const char * const *filters = {"kvm_pmu_reset", "kvm_pmu_init",
"dir_item_err", NULL};

Tzvetomir & steve,
>Since a triple pointer is difficult to manage in the code, you could have:
>
>       const char **e = NULL;
>
>
>               if (errs) {
>                        e = realloc(sizeof(*e), j + 1);
>                        e[j++] = filters[i];
>               }
>
>Then at the end:
>
>       if (errs)
>                *errs = e;
i have a concern here
when a double pointer is doing our work here without any overhead, why
we want to make it a triple pointer?

Thanks,
sameer.

On Fri, Mar 5, 2021 at 8:24 PM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> On Fri, 5 Mar 2021 09:39:46 -0500
> Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> > > > + * The @filters is an array of strings, where each string will be used to set
> > > > + * a function or functions to be traced.
> > > > + *
> > > > + * If @reset is true, then all functions in the filter are cleared before
> > > > + * adding functions from @filter. Otherwise, the functions set by @filter
> > > > + * will be appended to the filter file
> > > > + *
> > > > + * The @errs is an array of strings, where each string is a failed function
> > > > + * name
> > > > + *
> > > > + * returns -x (where x is number of failed filter srtings or it can be
> > > > + * 1 for general errors), or 0 if there are no errors.
> > > > + */
>
>
> We should for the return statement:
>
>  * returns -x on filter errorrs (where x is number of failed filter strings)
>  *         and @errs if non-NULL will be an allocated string array pointing
>  *         to the strings in @filter that failed, and must be freed with
>  *         free().
>  *
>  * returns 1 on general errors not related to setting the filter.
>  *         @errs is not set, even if supplied.
>  *
>  * returns 0 on success, and @errs is not set.
>
> -- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux