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? -- Steve > + if (dir) > + closedir(dir); > + tracefs_put_tracing_file(path); > + return fret; > +}