Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include "tracepoint.h"
0003 
0004 #include <errno.h>
0005 #include <fcntl.h>
0006 #include <stdio.h>
0007 #include <sys/param.h>
0008 #include <unistd.h>
0009 
0010 #include <api/fs/tracing_path.h>
0011 
0012 int tp_event_has_id(const char *dir_path, struct dirent *evt_dir)
0013 {
0014     char evt_path[MAXPATHLEN];
0015     int fd;
0016 
0017     snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, evt_dir->d_name);
0018     fd = open(evt_path, O_RDONLY);
0019     if (fd < 0)
0020         return -EINVAL;
0021     close(fd);
0022 
0023     return 0;
0024 }
0025 
0026 /*
0027  * Check whether event is in <debugfs_mount_point>/tracing/events
0028  */
0029 int is_valid_tracepoint(const char *event_string)
0030 {
0031     DIR *sys_dir, *evt_dir;
0032     struct dirent *sys_dirent, *evt_dirent;
0033     char evt_path[MAXPATHLEN];
0034     char *dir_path;
0035 
0036     sys_dir = tracing_events__opendir();
0037     if (!sys_dir)
0038         return 0;
0039 
0040     for_each_subsystem(sys_dir, sys_dirent) {
0041         dir_path = get_events_file(sys_dirent->d_name);
0042         if (!dir_path)
0043             continue;
0044         evt_dir = opendir(dir_path);
0045         if (!evt_dir)
0046             goto next;
0047 
0048         for_each_event(dir_path, evt_dir, evt_dirent) {
0049             snprintf(evt_path, MAXPATHLEN, "%s:%s",
0050                  sys_dirent->d_name, evt_dirent->d_name);
0051             if (!strcmp(evt_path, event_string)) {
0052                 closedir(evt_dir);
0053                 closedir(sys_dir);
0054                 return 1;
0055             }
0056         }
0057         closedir(evt_dir);
0058 next:
0059         put_events_file(dir_path);
0060     }
0061     closedir(sys_dir);
0062     return 0;
0063 }