diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/proc/base.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 6092a6e2c5a9..5ee46d3a5cac 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -2227,38 +2227,34 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
2227 | static struct task_struct *first_tid(struct task_struct *leader, | 2227 | static struct task_struct *first_tid(struct task_struct *leader, |
2228 | int tid, int nr) | 2228 | int tid, int nr) |
2229 | { | 2229 | { |
2230 | struct task_struct *pos = NULL; | 2230 | struct task_struct *pos; |
2231 | 2231 | ||
2232 | rcu_read_lock(); | 2232 | rcu_read_lock(); |
2233 | /* Attempt to start with the pid of a thread */ | 2233 | /* Attempt to start with the pid of a thread */ |
2234 | if (tid && (nr > 0)) { | 2234 | if (tid && (nr > 0)) { |
2235 | pos = find_task_by_pid(tid); | 2235 | pos = find_task_by_pid(tid); |
2236 | if (pos && (pos->group_leader != leader)) | 2236 | if (pos && (pos->group_leader == leader)) |
2237 | pos = NULL; | 2237 | goto found; |
2238 | if (pos) | ||
2239 | nr = 0; | ||
2240 | } | 2238 | } |
2241 | 2239 | ||
2242 | /* If nr exceeds the number of threads there is nothing todo */ | 2240 | /* If nr exceeds the number of threads there is nothing todo */ |
2243 | if (nr) { | 2241 | pos = NULL; |
2244 | if (nr >= get_nr_threads(leader)) | 2242 | if (nr && nr >= get_nr_threads(leader)) |
2245 | goto done; | 2243 | goto out; |
2246 | } | ||
2247 | 2244 | ||
2248 | /* If we haven't found our starting place yet start with the | 2245 | /* If we haven't found our starting place yet start |
2249 | * leader and walk nr threads forward. | 2246 | * with the leader and walk nr threads forward. |
2250 | */ | 2247 | */ |
2251 | if (!pos && (nr >= 0)) | 2248 | for (pos = leader; nr > 0; --nr) { |
2252 | pos = leader; | 2249 | pos = next_thread(pos); |
2253 | 2250 | if (pos == leader) { | |
2254 | for (; pos && pid_alive(pos); pos = next_thread(pos)) { | 2251 | pos = NULL; |
2255 | if (--nr > 0) | 2252 | goto out; |
2256 | continue; | 2253 | } |
2257 | get_task_struct(pos); | ||
2258 | goto done; | ||
2259 | } | 2254 | } |
2260 | pos = NULL; | 2255 | found: |
2261 | done: | 2256 | get_task_struct(pos); |
2257 | out: | ||
2262 | rcu_read_unlock(); | 2258 | rcu_read_unlock(); |
2263 | return pos; | 2259 | return pos; |
2264 | } | 2260 | } |