diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2006-06-26 03:25:52 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-26 12:58:25 -0400 |
commit | 9cc8cbc7f8b7bc3db48bf6d59a731af728e786ce (patch) | |
tree | fb94d7ee120c14d7a1b56005e8cd67bcba4083e6 /fs | |
parent | de7587343bfebc186995ad294e3de0da382eb9bc (diff) |
[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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/proc/base.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 8180579f8792..bbcaef9adb57 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -2040,34 +2040,32 @@ out: | |||
2040 | * In the case of a seek we start with &init_task and walk nr | 2040 | * In the case of a seek we start with &init_task and walk nr |
2041 | * threads past it. | 2041 | * threads past it. |
2042 | */ | 2042 | */ |
2043 | static struct task_struct *first_tgid(int tgid, int nr) | 2043 | static struct task_struct *first_tgid(int tgid, unsigned int nr) |
2044 | { | 2044 | { |
2045 | struct task_struct *pos = NULL; | 2045 | struct task_struct *pos; |
2046 | rcu_read_lock(); | 2046 | rcu_read_lock(); |
2047 | if (tgid && nr) { | 2047 | if (tgid && nr) { |
2048 | pos = find_task_by_pid(tgid); | 2048 | pos = find_task_by_pid(tgid); |
2049 | if (pos && !thread_group_leader(pos)) | 2049 | if (pos && thread_group_leader(pos)) |
2050 | pos = NULL; | 2050 | goto found; |
2051 | if (pos) | ||
2052 | nr = 0; | ||
2053 | } | 2051 | } |
2054 | /* If nr exceeds the number of processes get out quickly */ | 2052 | /* If nr exceeds the number of processes get out quickly */ |
2053 | pos = NULL; | ||
2055 | if (nr && nr >= nr_processes()) | 2054 | if (nr && nr >= nr_processes()) |
2056 | goto done; | 2055 | goto done; |
2057 | 2056 | ||
2058 | /* If we haven't found our starting place yet start with | 2057 | /* If we haven't found our starting place yet start with |
2059 | * the init_task and walk nr tasks forward. | 2058 | * the init_task and walk nr tasks forward. |
2060 | */ | 2059 | */ |
2061 | if (!pos && (nr >= 0)) | 2060 | for (pos = next_task(&init_task); nr > 0; --nr) { |
2062 | pos = next_task(&init_task); | 2061 | pos = next_task(pos); |
2063 | 2062 | if (pos == &init_task) { | |
2064 | for (; pos && pid_alive(pos); pos = next_task(pos)) { | 2063 | pos = NULL; |
2065 | if (--nr > 0) | 2064 | goto done; |
2066 | continue; | 2065 | } |
2067 | get_task_struct(pos); | ||
2068 | goto done; | ||
2069 | } | 2066 | } |
2070 | pos = NULL; | 2067 | found: |
2068 | get_task_struct(pos); | ||
2071 | done: | 2069 | done: |
2072 | rcu_read_unlock(); | 2070 | rcu_read_unlock(); |
2073 | return pos; | 2071 | return pos; |