Merge commit 'opendreambox/opendreambox-1.6' into vuplus-1.6
[vuplus_openembedded] / recipes / busybox / busybox-1.15.3 / vuplus / nptl_task.patch
1 --- busybox-1.15.3-org/include/libbb.h  2010-04-23 16:11:13.000000000 +0200
2 +++ busybox-1.15.3/include/libbb.h      2010-04-23 15:07:04.000000000 +0200
3 @@ -1279,6 +1279,8 @@
4         DIR *dir;
5         uint8_t shift_pages_to_bytes;
6         uint8_t shift_pages_to_kb;
7 +       DIR *taskdir;
8 +       unsigned parentpid;
9  /* Fields are set to 0/NULL if failed to determine (or not requested) */
10         uint16_t argv_len;
11         char *argv0;
12 --- busybox-1.15.3-org/libbb/procps.c   2010-04-23 16:11:13.000000000 +0200
13 +++ busybox-1.15.3/libbb/procps.c       2010-04-23 16:06:55.000000000 +0200
14 @@ -178,7 +178,7 @@
15  {
16         struct dirent *entry;
17         char buf[PROCPS_BUFSIZE];
18 -       char filename[sizeof("/proc//cmdline") + sizeof(int)*3];
19 +       char filename[sizeof("/proc//task//cmdline//") + sizeof(int)*6];
20         char *filename_tail;
21         long tasknice;
22         unsigned pid;
23 @@ -188,11 +188,14 @@
24         if (!sp)
25                 sp = alloc_procps_scan();
26  
27 -       for (;;) {
28 -               entry = readdir(sp->dir);
29 -               if (entry == NULL) {
30 -                       free_procps_scan(sp);
31 -                       return NULL;
32 +       for(;;) {
33 +               if (!sp->taskdir)
34 +                       break;
35 +               entry = readdir(sp->taskdir);
36 +               if(entry == NULL) {
37 +                       closedir(sp->taskdir);
38 +                       sp->taskdir = 0;
39 +                       break;
40                 }
41                 pid = bb_strtou(entry->d_name, NULL, 10);
42                 if (errno)
43 @@ -216,7 +219,7 @@
44                 }
45  #endif
46  
47 -               filename_tail = filename + sprintf(filename, "/proc/%u/", pid);
48 +               filename_tail = filename + sprintf(filename, "/proc/%u/task/%u/", sp->parentpid, pid);
49  
50                 if (flags & PSSCAN_UIDGID) {
51                         if (stat(filename, &sb))
52 @@ -468,6 +471,33 @@
53                 break;
54         } /* for (;;) */
55  
56 +       if(sp->taskdir)
57 +               return sp;
58 +
59 +       for (;;) {
60 +               entry = readdir(sp->dir);
61 +               if (entry == NULL) {
62 +                       free_procps_scan(sp);
63 +                       return NULL;
64 +               }
65 +               pid = bb_strtou(entry->d_name, NULL, 10);
66 +               if (errno)
67 +                       continue;
68 +
69 +               filename_tail = filename + sprintf(filename, "/proc/%u/", pid);
70 +
71 +               if (!sp->taskdir) {
72 +                       strcpy(filename_tail, "task");
73 +                       sp->taskdir = opendir(filename);
74 +                       if(!sp->taskdir) {
75 +                               // ignore processes without taskdir
76 +                               continue;
77 +                       }
78 +                       sp->parentpid = pid;
79 +                       return procps_scan(sp, flags);
80 +               }
81 +       }
82 +
83         return sp;
84  }
85