diff options
author | Shawn Bohrer <sbohrer@rgmadvisors.com> | 2010-11-21 11:09:39 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-11-26 22:33:04 -0500 |
commit | 008f29d3865828bb27e35d6d3fa889d0853b469f (patch) | |
tree | ed30036e47eb9fa91cf00b5ef8982f26c5a987eb /tools | |
parent | 9d1faba5fe410558099f13cfada2eab03186769d (diff) |
perf trace: Handle DT_UNKNOWN on filesystems that don't support d_type
Some filesystems like xfs and reiserfs will return DT_UNKNOWN for the
d_type. Handle this case by calling stat() to determine the type.
Cc: Andreas Schwab <schwab@linux-m68k.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1290355779-3276-1-git-send-email-sbohrer@rgmadvisors.com>
Signed-off-by: Shawn Bohrer <sbohrer@rgmadvisors.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-trace.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 86cfe3800e6b..4783ed8bd657 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -301,17 +301,34 @@ static int parse_scriptname(const struct option *opt __used, | |||
301 | return 0; | 301 | return 0; |
302 | } | 302 | } |
303 | 303 | ||
304 | #define for_each_lang(scripts_dir, lang_dirent, lang_next) \ | 304 | /* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */ |
305 | static int is_directory(const char *base_path, const struct dirent *dent) | ||
306 | { | ||
307 | char path[PATH_MAX]; | ||
308 | struct stat st; | ||
309 | |||
310 | sprintf(path, "%s/%s", base_path, dent->d_name); | ||
311 | if (stat(path, &st)) | ||
312 | return 0; | ||
313 | |||
314 | return S_ISDIR(st.st_mode); | ||
315 | } | ||
316 | |||
317 | #define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\ | ||
305 | while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \ | 318 | while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \ |
306 | lang_next) \ | 319 | lang_next) \ |
307 | if (lang_dirent.d_type == DT_DIR && \ | 320 | if ((lang_dirent.d_type == DT_DIR || \ |
321 | (lang_dirent.d_type == DT_UNKNOWN && \ | ||
322 | is_directory(scripts_path, &lang_dirent))) && \ | ||
308 | (strcmp(lang_dirent.d_name, ".")) && \ | 323 | (strcmp(lang_dirent.d_name, ".")) && \ |
309 | (strcmp(lang_dirent.d_name, ".."))) | 324 | (strcmp(lang_dirent.d_name, ".."))) |
310 | 325 | ||
311 | #define for_each_script(lang_dir, script_dirent, script_next) \ | 326 | #define for_each_script(lang_path, lang_dir, script_dirent, script_next)\ |
312 | while (!readdir_r(lang_dir, &script_dirent, &script_next) && \ | 327 | while (!readdir_r(lang_dir, &script_dirent, &script_next) && \ |
313 | script_next) \ | 328 | script_next) \ |
314 | if (script_dirent.d_type != DT_DIR) | 329 | if (script_dirent.d_type != DT_DIR && \ |
330 | (script_dirent.d_type != DT_UNKNOWN || \ | ||
331 | !is_directory(lang_path, &script_dirent))) | ||
315 | 332 | ||
316 | 333 | ||
317 | #define RECORD_SUFFIX "-record" | 334 | #define RECORD_SUFFIX "-record" |
@@ -466,14 +483,14 @@ static int list_available_scripts(const struct option *opt __used, | |||
466 | if (!scripts_dir) | 483 | if (!scripts_dir) |
467 | return -1; | 484 | return -1; |
468 | 485 | ||
469 | for_each_lang(scripts_dir, lang_dirent, lang_next) { | 486 | for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) { |
470 | snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, | 487 | snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, |
471 | lang_dirent.d_name); | 488 | lang_dirent.d_name); |
472 | lang_dir = opendir(lang_path); | 489 | lang_dir = opendir(lang_path); |
473 | if (!lang_dir) | 490 | if (!lang_dir) |
474 | continue; | 491 | continue; |
475 | 492 | ||
476 | for_each_script(lang_dir, script_dirent, script_next) { | 493 | for_each_script(lang_path, lang_dir, script_dirent, script_next) { |
477 | script_root = strdup(script_dirent.d_name); | 494 | script_root = strdup(script_dirent.d_name); |
478 | str = ends_with(script_root, REPORT_SUFFIX); | 495 | str = ends_with(script_root, REPORT_SUFFIX); |
479 | if (str) { | 496 | if (str) { |
@@ -514,14 +531,14 @@ static char *get_script_path(const char *script_root, const char *suffix) | |||
514 | if (!scripts_dir) | 531 | if (!scripts_dir) |
515 | return NULL; | 532 | return NULL; |
516 | 533 | ||
517 | for_each_lang(scripts_dir, lang_dirent, lang_next) { | 534 | for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) { |
518 | snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, | 535 | snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, |
519 | lang_dirent.d_name); | 536 | lang_dirent.d_name); |
520 | lang_dir = opendir(lang_path); | 537 | lang_dir = opendir(lang_path); |
521 | if (!lang_dir) | 538 | if (!lang_dir) |
522 | continue; | 539 | continue; |
523 | 540 | ||
524 | for_each_script(lang_dir, script_dirent, script_next) { | 541 | for_each_script(lang_path, lang_dir, script_dirent, script_next) { |
525 | __script_root = strdup(script_dirent.d_name); | 542 | __script_root = strdup(script_dirent.d_name); |
526 | str = ends_with(__script_root, suffix); | 543 | str = ends_with(__script_root, suffix); |
527 | if (str) { | 544 | if (str) { |