Re: [PATCH v2 5/6] libtracefs: Add new tracefs API tracefs_instances_walk()

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

 



On Thu, Nov 12, 2020 at 3:31 AM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> On Tue, 10 Nov 2020 14:22:48 +0200
> "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> wrote:
> \> +
> > +/**
> > + * tracefs_instances_walk - Iterate through all ftrace instances in the system
> > + * @callback: user callback, called for each instance. Instance name is passed
> > + *         as input parameter. If the @callback returns non-zero,
> > + *         the iteration stops.
> > + * @context: user context, passed to the @callback.
> > + *
> > + * Returns -1 in case of an error, 0 otherwise.
> > + */
> > +int tracefs_instances_walk(int (*callback)(const char *, void *), void *context)
> > +{
> > +     struct dirent *dent;
> > +     char *path = NULL;
> > +     DIR *dir = NULL;
> > +     struct stat st;
> > +     int fret = -1;
> > +     int ret;
> > +
> > +     path = tracefs_get_tracing_file("instances");
> > +     if (!path)
> > +             return -1;
> > +     ret = stat(path, &st);
> > +     if (ret < 0 || !S_ISDIR(st.st_mode))
> > +             goto out;
> > +
> > +     dir = opendir(path);
> > +     if (!dir)
> > +             goto out;
> > +     fret = 0;
> > +     while ((dent = readdir(dir))) {
> > +             char *instance;
> > +
> > +             if (strcmp(dent->d_name, ".") == 0 ||
> > +                 strcmp(dent->d_name, "..") == 0)
> > +                     continue;
> > +             instance = trace_append_file(path, dent->d_name);
> > +             ret = stat(instance, &st);
> > +             free(instance);
> > +             if (ret < 0 || !S_ISDIR(st.st_mode))
> > +                     continue;
> > +             if (callback(dent->d_name, context))
>
> Should we notify the caller of this function if the callback returned
> non zero?
>
>
> > +                     break;
> > +     }
> > +
> > +out:
>
> Hmm, would dir ever be anything but non NULL here?
>
It could be NULL if opendir() or stat() fails.

Thanks, Steve! I'll address your comments in the next version of the patch set.
> -- Steve
>
> > +     if (dir)
> > +             closedir(dir);
> > +     tracefs_put_tracing_file(path);
> > +     return fret;
> > +}



-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center



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

  Powered by Linux