forked from Minki/linux
[PATCH] simply fix first_tgid
Like the bug Oleg spotted in first_tid there was also a small off by one error in first_tgid, when a seek was done on the /proc directory. This fixes that and changes the code structure to make it a little more obvious what is going on. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Cc: Oleg Nesterov <oleg@tv-sign.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
de7587343b
commit
9cc8cbc7f8
@ -2040,34 +2040,32 @@ out:
|
|||||||
* In the case of a seek we start with &init_task and walk nr
|
* In the case of a seek we start with &init_task and walk nr
|
||||||
* threads past it.
|
* threads past it.
|
||||||
*/
|
*/
|
||||||
static struct task_struct *first_tgid(int tgid, int nr)
|
static struct task_struct *first_tgid(int tgid, unsigned int nr)
|
||||||
{
|
{
|
||||||
struct task_struct *pos = NULL;
|
struct task_struct *pos;
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
if (tgid && nr) {
|
if (tgid && nr) {
|
||||||
pos = find_task_by_pid(tgid);
|
pos = find_task_by_pid(tgid);
|
||||||
if (pos && !thread_group_leader(pos))
|
if (pos && thread_group_leader(pos))
|
||||||
pos = NULL;
|
goto found;
|
||||||
if (pos)
|
|
||||||
nr = 0;
|
|
||||||
}
|
}
|
||||||
/* If nr exceeds the number of processes get out quickly */
|
/* If nr exceeds the number of processes get out quickly */
|
||||||
|
pos = NULL;
|
||||||
if (nr && nr >= nr_processes())
|
if (nr && nr >= nr_processes())
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* If we haven't found our starting place yet start with
|
/* If we haven't found our starting place yet start with
|
||||||
* the init_task and walk nr tasks forward.
|
* the init_task and walk nr tasks forward.
|
||||||
*/
|
*/
|
||||||
if (!pos && (nr >= 0))
|
for (pos = next_task(&init_task); nr > 0; --nr) {
|
||||||
pos = next_task(&init_task);
|
pos = next_task(pos);
|
||||||
|
if (pos == &init_task) {
|
||||||
for (; pos && pid_alive(pos); pos = next_task(pos)) {
|
pos = NULL;
|
||||||
if (--nr > 0)
|
goto done;
|
||||||
continue;
|
}
|
||||||
get_task_struct(pos);
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
pos = NULL;
|
found:
|
||||||
|
get_task_struct(pos);
|
||||||
done:
|
done:
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
return pos;
|
return pos;
|
||||||
|
Loading…
Reference in New Issue
Block a user