diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-08 10:53:02 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-05-12 10:26:58 -0400 |
commit | 22a9f41b555673e7499b97acf3ffb07bf0af31ad (patch) | |
tree | d15ff34cc873566d170aa845b178d612376c3d2f /tools/perf/util/parse-events.c | |
parent | 7839b9f32e45075d9eb48da8480faef3dbd019f0 (diff) |
perf tools: Use readdir() instead of deprecated readdir_r()
The readdir() function is thread safe as long as just one thread uses a
DIR, which is the case when parsing tracepoint event definitions, to
avoid breaking the build with glibc-2.23.90 (upcoming 2.24), use it
instead of readdir_r().
See: http://man7.org/linux/man-pages/man3/readdir.3.html
"However, in modern implementations (including the glibc implementation),
concurrent calls to readdir() that specify different directory streams
are thread-safe. In cases where multiple threads must read from the
same directory stream, using readdir() with external synchronization is
still preferable to the use of the deprecated readdir_r(3) function."
Noticed while building on a Fedora Rawhide docker container.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-wddn49r6bz6wq4ee3dxbl7lo@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r-- | tools/perf/util/parse-events.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 4c19d5e79d8c..bcbc983d4b12 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -138,11 +138,11 @@ struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { | |||
138 | #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) | 138 | #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) |
139 | #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) | 139 | #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) |
140 | 140 | ||
141 | #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ | 141 | #define for_each_subsystem(sys_dir, sys_dirent) \ |
142 | while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ | 142 | while ((sys_dirent = readdir(sys_dir)) != NULL) \ |
143 | if (sys_dirent.d_type == DT_DIR && \ | 143 | if (sys_dirent->d_type == DT_DIR && \ |
144 | (strcmp(sys_dirent.d_name, ".")) && \ | 144 | (strcmp(sys_dirent->d_name, ".")) && \ |
145 | (strcmp(sys_dirent.d_name, ".."))) | 145 | (strcmp(sys_dirent->d_name, ".."))) |
146 | 146 | ||
147 | static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) | 147 | static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) |
148 | { | 148 | { |
@@ -159,12 +159,12 @@ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) | |||
159 | return 0; | 159 | return 0; |
160 | } | 160 | } |
161 | 161 | ||
162 | #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \ | 162 | #define for_each_event(sys_dirent, evt_dir, evt_dirent) \ |
163 | while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ | 163 | while ((evt_dirent = readdir(evt_dir)) != NULL) \ |
164 | if (evt_dirent.d_type == DT_DIR && \ | 164 | if (evt_dirent->d_type == DT_DIR && \ |
165 | (strcmp(evt_dirent.d_name, ".")) && \ | 165 | (strcmp(evt_dirent->d_name, ".")) && \ |
166 | (strcmp(evt_dirent.d_name, "..")) && \ | 166 | (strcmp(evt_dirent->d_name, "..")) && \ |
167 | (!tp_event_has_id(&sys_dirent, &evt_dirent))) | 167 | (!tp_event_has_id(sys_dirent, evt_dirent))) |
168 | 168 | ||
169 | #define MAX_EVENT_LENGTH 512 | 169 | #define MAX_EVENT_LENGTH 512 |
170 | 170 | ||
@@ -173,7 +173,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) | |||
173 | { | 173 | { |
174 | struct tracepoint_path *path = NULL; | 174 | struct tracepoint_path *path = NULL; |
175 | DIR *sys_dir, *evt_dir; | 175 | DIR *sys_dir, *evt_dir; |
176 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | 176 | struct dirent *sys_dirent, *evt_dirent; |
177 | char id_buf[24]; | 177 | char id_buf[24]; |
178 | int fd; | 178 | int fd; |
179 | u64 id; | 179 | u64 id; |
@@ -184,18 +184,18 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) | |||
184 | if (!sys_dir) | 184 | if (!sys_dir) |
185 | return NULL; | 185 | return NULL; |
186 | 186 | ||
187 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { | 187 | for_each_subsystem(sys_dir, sys_dirent) { |
188 | 188 | ||
189 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, | 189 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, |
190 | sys_dirent.d_name); | 190 | sys_dirent->d_name); |
191 | evt_dir = opendir(dir_path); | 191 | evt_dir = opendir(dir_path); |
192 | if (!evt_dir) | 192 | if (!evt_dir) |
193 | continue; | 193 | continue; |
194 | 194 | ||
195 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { | 195 | for_each_event(sys_dirent, evt_dir, evt_dirent) { |
196 | 196 | ||
197 | snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, | 197 | snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, |
198 | evt_dirent.d_name); | 198 | evt_dirent->d_name); |
199 | fd = open(evt_path, O_RDONLY); | 199 | fd = open(evt_path, O_RDONLY); |
200 | if (fd < 0) | 200 | if (fd < 0) |
201 | continue; | 201 | continue; |
@@ -220,9 +220,9 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) | |||
220 | free(path); | 220 | free(path); |
221 | return NULL; | 221 | return NULL; |
222 | } | 222 | } |
223 | strncpy(path->system, sys_dirent.d_name, | 223 | strncpy(path->system, sys_dirent->d_name, |
224 | MAX_EVENT_LENGTH); | 224 | MAX_EVENT_LENGTH); |
225 | strncpy(path->name, evt_dirent.d_name, | 225 | strncpy(path->name, evt_dirent->d_name, |
226 | MAX_EVENT_LENGTH); | 226 | MAX_EVENT_LENGTH); |
227 | return path; | 227 | return path; |
228 | } | 228 | } |
@@ -1812,7 +1812,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob, | |||
1812 | bool name_only) | 1812 | bool name_only) |
1813 | { | 1813 | { |
1814 | DIR *sys_dir, *evt_dir; | 1814 | DIR *sys_dir, *evt_dir; |
1815 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | 1815 | struct dirent *sys_dirent, *evt_dirent; |
1816 | char evt_path[MAXPATHLEN]; | 1816 | char evt_path[MAXPATHLEN]; |
1817 | char dir_path[MAXPATHLEN]; | 1817 | char dir_path[MAXPATHLEN]; |
1818 | char **evt_list = NULL; | 1818 | char **evt_list = NULL; |
@@ -1830,20 +1830,20 @@ restart: | |||
1830 | goto out_close_sys_dir; | 1830 | goto out_close_sys_dir; |
1831 | } | 1831 | } |
1832 | 1832 | ||
1833 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { | 1833 | for_each_subsystem(sys_dir, sys_dirent) { |
1834 | if (subsys_glob != NULL && | 1834 | if (subsys_glob != NULL && |
1835 | !strglobmatch(sys_dirent.d_name, subsys_glob)) | 1835 | !strglobmatch(sys_dirent->d_name, subsys_glob)) |
1836 | continue; | 1836 | continue; |
1837 | 1837 | ||
1838 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, | 1838 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, |
1839 | sys_dirent.d_name); | 1839 | sys_dirent->d_name); |
1840 | evt_dir = opendir(dir_path); | 1840 | evt_dir = opendir(dir_path); |
1841 | if (!evt_dir) | 1841 | if (!evt_dir) |
1842 | continue; | 1842 | continue; |
1843 | 1843 | ||
1844 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { | 1844 | for_each_event(sys_dirent, evt_dir, evt_dirent) { |
1845 | if (event_glob != NULL && | 1845 | if (event_glob != NULL && |
1846 | !strglobmatch(evt_dirent.d_name, event_glob)) | 1846 | !strglobmatch(evt_dirent->d_name, event_glob)) |
1847 | continue; | 1847 | continue; |
1848 | 1848 | ||
1849 | if (!evt_num_known) { | 1849 | if (!evt_num_known) { |
@@ -1852,7 +1852,7 @@ restart: | |||
1852 | } | 1852 | } |
1853 | 1853 | ||
1854 | snprintf(evt_path, MAXPATHLEN, "%s:%s", | 1854 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
1855 | sys_dirent.d_name, evt_dirent.d_name); | 1855 | sys_dirent->d_name, evt_dirent->d_name); |
1856 | 1856 | ||
1857 | evt_list[evt_i] = strdup(evt_path); | 1857 | evt_list[evt_i] = strdup(evt_path); |
1858 | if (evt_list[evt_i] == NULL) | 1858 | if (evt_list[evt_i] == NULL) |
@@ -1905,7 +1905,7 @@ out_close_sys_dir: | |||
1905 | int is_valid_tracepoint(const char *event_string) | 1905 | int is_valid_tracepoint(const char *event_string) |
1906 | { | 1906 | { |
1907 | DIR *sys_dir, *evt_dir; | 1907 | DIR *sys_dir, *evt_dir; |
1908 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | 1908 | struct dirent *sys_dirent, *evt_dirent; |
1909 | char evt_path[MAXPATHLEN]; | 1909 | char evt_path[MAXPATHLEN]; |
1910 | char dir_path[MAXPATHLEN]; | 1910 | char dir_path[MAXPATHLEN]; |
1911 | 1911 | ||
@@ -1913,17 +1913,17 @@ int is_valid_tracepoint(const char *event_string) | |||
1913 | if (!sys_dir) | 1913 | if (!sys_dir) |
1914 | return 0; | 1914 | return 0; |
1915 | 1915 | ||
1916 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { | 1916 | for_each_subsystem(sys_dir, sys_dirent) { |
1917 | 1917 | ||
1918 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, | 1918 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, |
1919 | sys_dirent.d_name); | 1919 | sys_dirent->d_name); |
1920 | evt_dir = opendir(dir_path); | 1920 | evt_dir = opendir(dir_path); |
1921 | if (!evt_dir) | 1921 | if (!evt_dir) |
1922 | continue; | 1922 | continue; |
1923 | 1923 | ||
1924 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { | 1924 | for_each_event(sys_dirent, evt_dir, evt_dirent) { |
1925 | snprintf(evt_path, MAXPATHLEN, "%s:%s", | 1925 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
1926 | sys_dirent.d_name, evt_dirent.d_name); | 1926 | sys_dirent->d_name, evt_dirent->d_name); |
1927 | if (!strcmp(evt_path, event_string)) { | 1927 | if (!strcmp(evt_path, event_string)) { |
1928 | closedir(evt_dir); | 1928 | closedir(evt_dir); |
1929 | closedir(sys_dir); | 1929 | closedir(sys_dir); |