aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c70
1 files changed, 34 insertions, 36 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 368d1e1561f7..48840556bf2d 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1253,21 +1253,19 @@ static int is_directory(const char *base_path, const struct dirent *dent)
1253 return S_ISDIR(st.st_mode); 1253 return S_ISDIR(st.st_mode);
1254} 1254}
1255 1255
1256#define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\ 1256#define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
1257 while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \ 1257 while ((lang_dirent = readdir(scripts_dir)) != NULL) \
1258 lang_next) \ 1258 if ((lang_dirent->d_type == DT_DIR || \
1259 if ((lang_dirent.d_type == DT_DIR || \ 1259 (lang_dirent->d_type == DT_UNKNOWN && \
1260 (lang_dirent.d_type == DT_UNKNOWN && \ 1260 is_directory(scripts_path, lang_dirent))) && \
1261 is_directory(scripts_path, &lang_dirent))) && \ 1261 (strcmp(lang_dirent->d_name, ".")) && \
1262 (strcmp(lang_dirent.d_name, ".")) && \ 1262 (strcmp(lang_dirent->d_name, "..")))
1263 (strcmp(lang_dirent.d_name, ".."))) 1263
1264 1264#define for_each_script(lang_path, lang_dir, script_dirent) \
1265#define for_each_script(lang_path, lang_dir, script_dirent, script_next)\ 1265 while ((script_dirent = readdir(lang_dir)) != NULL) \
1266 while (!readdir_r(lang_dir, &script_dirent, &script_next) && \ 1266 if (script_dirent->d_type != DT_DIR && \
1267 script_next) \ 1267 (script_dirent->d_type != DT_UNKNOWN || \
1268 if (script_dirent.d_type != DT_DIR && \ 1268 !is_directory(lang_path, script_dirent)))
1269 (script_dirent.d_type != DT_UNKNOWN || \
1270 !is_directory(lang_path, &script_dirent)))
1271 1269
1272 1270
1273#define RECORD_SUFFIX "-record" 1271#define RECORD_SUFFIX "-record"
@@ -1413,7 +1411,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
1413 const char *s __maybe_unused, 1411 const char *s __maybe_unused,
1414 int unset __maybe_unused) 1412 int unset __maybe_unused)
1415{ 1413{
1416 struct dirent *script_next, *lang_next, script_dirent, lang_dirent; 1414 struct dirent *script_dirent, *lang_dirent;
1417 char scripts_path[MAXPATHLEN]; 1415 char scripts_path[MAXPATHLEN];
1418 DIR *scripts_dir, *lang_dir; 1416 DIR *scripts_dir, *lang_dir;
1419 char script_path[MAXPATHLEN]; 1417 char script_path[MAXPATHLEN];
@@ -1428,19 +1426,19 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
1428 if (!scripts_dir) 1426 if (!scripts_dir)
1429 return -1; 1427 return -1;
1430 1428
1431 for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) { 1429 for_each_lang(scripts_path, scripts_dir, lang_dirent) {
1432 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, 1430 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
1433 lang_dirent.d_name); 1431 lang_dirent->d_name);
1434 lang_dir = opendir(lang_path); 1432 lang_dir = opendir(lang_path);
1435 if (!lang_dir) 1433 if (!lang_dir)
1436 continue; 1434 continue;
1437 1435
1438 for_each_script(lang_path, lang_dir, script_dirent, script_next) { 1436 for_each_script(lang_path, lang_dir, script_dirent) {
1439 script_root = get_script_root(&script_dirent, REPORT_SUFFIX); 1437 script_root = get_script_root(script_dirent, REPORT_SUFFIX);
1440 if (script_root) { 1438 if (script_root) {
1441 desc = script_desc__findnew(script_root); 1439 desc = script_desc__findnew(script_root);
1442 snprintf(script_path, MAXPATHLEN, "%s/%s", 1440 snprintf(script_path, MAXPATHLEN, "%s/%s",
1443 lang_path, script_dirent.d_name); 1441 lang_path, script_dirent->d_name);
1444 read_script_info(desc, script_path); 1442 read_script_info(desc, script_path);
1445 free(script_root); 1443 free(script_root);
1446 } 1444 }
@@ -1528,7 +1526,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
1528 */ 1526 */
1529int find_scripts(char **scripts_array, char **scripts_path_array) 1527int find_scripts(char **scripts_array, char **scripts_path_array)
1530{ 1528{
1531 struct dirent *script_next, *lang_next, script_dirent, lang_dirent; 1529 struct dirent *script_dirent, *lang_dirent;
1532 char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN]; 1530 char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
1533 DIR *scripts_dir, *lang_dir; 1531 DIR *scripts_dir, *lang_dir;
1534 struct perf_session *session; 1532 struct perf_session *session;
@@ -1551,9 +1549,9 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
1551 return -1; 1549 return -1;
1552 } 1550 }
1553 1551
1554 for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) { 1552 for_each_lang(scripts_path, scripts_dir, lang_dirent) {
1555 snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path, 1553 snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
1556 lang_dirent.d_name); 1554 lang_dirent->d_name);
1557#ifdef NO_LIBPERL 1555#ifdef NO_LIBPERL
1558 if (strstr(lang_path, "perl")) 1556 if (strstr(lang_path, "perl"))
1559 continue; 1557 continue;
@@ -1567,16 +1565,16 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
1567 if (!lang_dir) 1565 if (!lang_dir)
1568 continue; 1566 continue;
1569 1567
1570 for_each_script(lang_path, lang_dir, script_dirent, script_next) { 1568 for_each_script(lang_path, lang_dir, script_dirent) {
1571 /* Skip those real time scripts: xxxtop.p[yl] */ 1569 /* Skip those real time scripts: xxxtop.p[yl] */
1572 if (strstr(script_dirent.d_name, "top.")) 1570 if (strstr(script_dirent->d_name, "top."))
1573 continue; 1571 continue;
1574 sprintf(scripts_path_array[i], "%s/%s", lang_path, 1572 sprintf(scripts_path_array[i], "%s/%s", lang_path,
1575 script_dirent.d_name); 1573 script_dirent->d_name);
1576 temp = strchr(script_dirent.d_name, '.'); 1574 temp = strchr(script_dirent->d_name, '.');
1577 snprintf(scripts_array[i], 1575 snprintf(scripts_array[i],
1578 (temp - script_dirent.d_name) + 1, 1576 (temp - script_dirent->d_name) + 1,
1579 "%s", script_dirent.d_name); 1577 "%s", script_dirent->d_name);
1580 1578
1581 if (check_ev_match(lang_path, 1579 if (check_ev_match(lang_path,
1582 scripts_array[i], session)) 1580 scripts_array[i], session))
@@ -1594,7 +1592,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
1594 1592
1595static char *get_script_path(const char *script_root, const char *suffix) 1593static char *get_script_path(const char *script_root, const char *suffix)
1596{ 1594{
1597 struct dirent *script_next, *lang_next, script_dirent, lang_dirent; 1595 struct dirent *script_dirent, *lang_dirent;
1598 char scripts_path[MAXPATHLEN]; 1596 char scripts_path[MAXPATHLEN];
1599 char script_path[MAXPATHLEN]; 1597 char script_path[MAXPATHLEN];
1600 DIR *scripts_dir, *lang_dir; 1598 DIR *scripts_dir, *lang_dir;
@@ -1607,21 +1605,21 @@ static char *get_script_path(const char *script_root, const char *suffix)
1607 if (!scripts_dir) 1605 if (!scripts_dir)
1608 return NULL; 1606 return NULL;
1609 1607
1610 for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) { 1608 for_each_lang(scripts_path, scripts_dir, lang_dirent) {
1611 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, 1609 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
1612 lang_dirent.d_name); 1610 lang_dirent->d_name);
1613 lang_dir = opendir(lang_path); 1611 lang_dir = opendir(lang_path);
1614 if (!lang_dir) 1612 if (!lang_dir)
1615 continue; 1613 continue;
1616 1614
1617 for_each_script(lang_path, lang_dir, script_dirent, script_next) { 1615 for_each_script(lang_path, lang_dir, script_dirent) {
1618 __script_root = get_script_root(&script_dirent, suffix); 1616 __script_root = get_script_root(script_dirent, suffix);
1619 if (__script_root && !strcmp(script_root, __script_root)) { 1617 if (__script_root && !strcmp(script_root, __script_root)) {
1620 free(__script_root); 1618 free(__script_root);
1621 closedir(lang_dir); 1619 closedir(lang_dir);
1622 closedir(scripts_dir); 1620 closedir(scripts_dir);
1623 snprintf(script_path, MAXPATHLEN, "%s/%s", 1621 snprintf(script_path, MAXPATHLEN, "%s/%s",
1624 lang_path, script_dirent.d_name); 1622 lang_path, script_dirent->d_name);
1625 return strdup(script_path); 1623 return strdup(script_path);
1626 } 1624 }
1627 free(__script_root); 1625 free(__script_root);