perf tools: Fix find tids routine by excluding "." and ".."
Gui Jianfeng [Wed, 16 Jun 2010 05:21:44 +0000 (13:21 +0800)]
Introduce a filter function to skip "." and ".." directories when calculating
tid number, otherwise tid 0 will be included in the all_tid result array.

Cc: Ingo Molnar <mingo@elte.hu>
LKML-Reference: <4C185F68.1020505@cn.fujitsu.com>
Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

tools/perf/util/thread.c

index 1f7ecd4..9a448b4 100644 (file)
@@ -7,6 +7,15 @@
 #include "util.h"
 #include "debug.h"
 
+/* Skip "." and ".." directories */
+static int filter(const struct dirent *dir)
+{
+       if (dir->d_name[0] == '.')
+               return 0;
+       else
+               return 1;
+}
+
 int find_all_tid(int pid, pid_t ** all_tid)
 {
        char name[256];
@@ -16,7 +25,7 @@ int find_all_tid(int pid, pid_t ** all_tid)
        int i;
 
        sprintf(name, "/proc/%d/task", pid);
-       items = scandir(name, &namelist, NULL, NULL);
+       items = scandir(name, &namelist, filter, NULL);
        if (items <= 0)
                 return -ENOENT;
        *all_tid = malloc(sizeof(pid_t) * items);