Commit a5d2bf7b authored by Ingo Molnar's avatar Ingo Molnar

[PATCH] hide-threads-2.5.34-C1

I fixed up the 'remove thread group inferiors from the tasklist' patch. I
think i managed to find a reasonably good construct to iterate over all
threads:

	do_each_thread(g, p) {
		...
	} while_each_thread(g, p);

the only caveat with this is that the construct suggests a single-loop -
while it's two loops internally - and 'break' will not work. I added a
comment to sched.h that warns about this, but perhaps it would help more
to have naming that suggests two loops:

	for_each_process_do_each_thread(g, p) {
		...
	} while_each_thread(g, p);

but this looks a bit too long. I dont know. We might as well use it all
unrolled and no helper macros - although with the above construct it's
pretty straightforward to iterate over all threads in the system.
parent 8fd85682
...@@ -608,16 +608,17 @@ static inline void free_vm86_irq(int irqnumber) ...@@ -608,16 +608,17 @@ static inline void free_vm86_irq(int irqnumber)
static inline int task_valid(struct task_struct *tsk) static inline int task_valid(struct task_struct *tsk)
{ {
struct task_struct *p; struct task_struct *g, *p;
int ret = 0; int ret = 0;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p)
if ((p == tsk) && (p->sig)) { if ((p == tsk) && (p->sig)) {
ret = 1; ret = 1;
break; goto out;
}
} }
while_each_thread(g, p);
out:
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
return ret; return ret;
} }
......
...@@ -299,7 +299,7 @@ static void send_sig_all(int sig) ...@@ -299,7 +299,7 @@ static void send_sig_all(int sig)
{ {
struct task_struct *p; struct task_struct *p;
for_each_task(p) { for_each_process(p) {
if (p->mm && p->pid != 1) if (p->mm && p->pid != 1)
/* Not swapper, init nor kernel thread */ /* Not swapper, init nor kernel thread */
force_sig(sig, p); force_sig(sig, p);
......
...@@ -496,7 +496,7 @@ void do_tty_hangup(void *data) ...@@ -496,7 +496,7 @@ void do_tty_hangup(void *data)
} }
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { for_each_process(p) {
if ((tty->session > 0) && (p->session == tty->session) && if ((tty->session > 0) && (p->session == tty->session) &&
p->leader) { p->leader) {
send_sig(SIGHUP,p,1); send_sig(SIGHUP,p,1);
...@@ -598,7 +598,7 @@ void disassociate_ctty(int on_exit) ...@@ -598,7 +598,7 @@ void disassociate_ctty(int on_exit)
tty->pgrp = -1; tty->pgrp = -1;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) for_each_process(p)
if (p->session == current->session) if (p->session == current->session)
p->tty = NULL; p->tty = NULL;
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
...@@ -1223,7 +1223,7 @@ static void release_dev(struct file * filp) ...@@ -1223,7 +1223,7 @@ static void release_dev(struct file * filp)
struct task_struct *p; struct task_struct *p;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { for_each_process(p) {
if (p->tty == tty || (o_tty && p->tty == o_tty)) if (p->tty == tty || (o_tty && p->tty == o_tty))
p->tty = NULL; p->tty = NULL;
} }
...@@ -1561,7 +1561,7 @@ static int tiocsctty(struct tty_struct *tty, int arg) ...@@ -1561,7 +1561,7 @@ static int tiocsctty(struct tty_struct *tty, int arg)
struct task_struct *p; struct task_struct *p;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) for_each_process(p)
if (p->tty == tty) if (p->tty == tty)
p->tty = NULL; p->tty = NULL;
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
...@@ -1834,7 +1834,7 @@ static void __do_SAK(void *arg) ...@@ -1834,7 +1834,7 @@ static void __do_SAK(void *arg)
if (tty->driver.flush_buffer) if (tty->driver.flush_buffer)
tty->driver.flush_buffer(tty); tty->driver.flush_buffer(tty);
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { for_each_process(p) {
if ((p->tty == tty) || if ((p->tty == tty) ||
((session > 0) && (p->session == session))) { ((session > 0) && (p->session == session))) {
printk(KERN_NOTICE "SAK: killed process %d" printk(KERN_NOTICE "SAK: killed process %d"
......
...@@ -493,7 +493,7 @@ void send_sigio(struct fown_struct *fown, int fd, int band) ...@@ -493,7 +493,7 @@ void send_sigio(struct fown_struct *fown, int fd, int band)
send_sigio_to_task(p, fown, fd, band); send_sigio_to_task(p, fown, fd, band);
goto out_unlock_task; goto out_unlock_task;
} }
for_each_task(p) { for_each_process(p) {
int match = p->pid; int match = p->pid;
if (pid < 0) if (pid < 0)
match = -p->pgrp; match = -p->pgrp;
...@@ -531,7 +531,7 @@ int send_sigurg(struct fown_struct *fown) ...@@ -531,7 +531,7 @@ int send_sigurg(struct fown_struct *fown)
send_sigurg_to_task(p, fown); send_sigurg_to_task(p, fown);
goto out_unlock_task; goto out_unlock_task;
} }
for_each_task(p) { for_each_process(p) {
int match = p->pid; int match = p->pid;
if (pid < 0) if (pid < 0)
match = -p->pgrp; match = -p->pgrp;
......
...@@ -883,11 +883,11 @@ asmlinkage long sys_mount(char * dev_name, char * dir_name, char * type, ...@@ -883,11 +883,11 @@ asmlinkage long sys_mount(char * dev_name, char * dir_name, char * type,
static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd) static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
{ {
struct task_struct *p; struct task_struct *g, *p;
struct fs_struct *fs; struct fs_struct *fs;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p) {
task_lock(p); task_lock(p);
fs = p->fs; fs = p->fs;
if (fs) { if (fs) {
...@@ -900,7 +900,7 @@ static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd) ...@@ -900,7 +900,7 @@ static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
put_fs_struct(fs); put_fs_struct(fs);
} else } else
task_unlock(p); task_unlock(p);
} } while_each_thread(g, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
} }
...@@ -1012,7 +1012,7 @@ static void __init init_mount_tree(void) ...@@ -1012,7 +1012,7 @@ static void __init init_mount_tree(void)
{ {
struct vfsmount *mnt; struct vfsmount *mnt;
struct namespace *namespace; struct namespace *namespace;
struct task_struct *p; struct task_struct *g, *p;
mnt = do_kern_mount("rootfs", 0, "rootfs", NULL); mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
if (IS_ERR(mnt)) if (IS_ERR(mnt))
...@@ -1028,10 +1028,10 @@ static void __init init_mount_tree(void) ...@@ -1028,10 +1028,10 @@ static void __init init_mount_tree(void)
init_task.namespace = namespace; init_task.namespace = namespace;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p) {
get_namespace(namespace); get_namespace(namespace);
p->namespace = namespace; p->namespace = namespace;
} } while_each_thread(g, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
set_fs_pwd(current->fs, namespace->root, namespace->root->mnt_root); set_fs_pwd(current->fs, namespace->root, namespace->root->mnt_root);
......
...@@ -1136,7 +1136,7 @@ static int get_pid_list(int index, unsigned int *pids) ...@@ -1136,7 +1136,7 @@ static int get_pid_list(int index, unsigned int *pids)
index--; index--;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { for_each_process(p) {
int pid = p->pid; int pid = p->pid;
if (!pid) if (!pid)
continue; continue;
......
...@@ -235,7 +235,9 @@ int proc_fill_super(struct super_block *s, void *data, int silent) ...@@ -235,7 +235,9 @@ int proc_fill_super(struct super_block *s, void *data, int silent)
* Fixup the root inode's nlink value * Fixup the root inode's nlink value
*/ */
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) if (p->pid) root_inode->i_nlink++; for_each_process(p)
if (p->pid)
root_inode->i_nlink++;
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
s->s_root = d_alloc_root(root_inode); s->s_root = d_alloc_root(root_inode);
if (!s->s_root) if (!s->s_root)
......
...@@ -761,11 +761,13 @@ static inline void remove_wait_queue_locked(wait_queue_head_t *q, ...@@ -761,11 +761,13 @@ static inline void remove_wait_queue_locked(wait_queue_head_t *q,
#define add_parent(p, parent) list_add_tail(&(p)->sibling,&(parent)->children) #define add_parent(p, parent) list_add_tail(&(p)->sibling,&(parent)->children)
#define REMOVE_LINKS(p) do { \ #define REMOVE_LINKS(p) do { \
if (thread_group_leader(p)) \
list_del_init(&(p)->tasks); \ list_del_init(&(p)->tasks); \
remove_parent(p); \ remove_parent(p); \
} while (0) } while (0)
#define SET_LINKS(p) do { \ #define SET_LINKS(p) do { \
if (thread_group_leader(p)) \
list_add_tail(&(p)->tasks,&init_task.tasks); \ list_add_tail(&(p)->tasks,&init_task.tasks); \
add_parent(p, (p)->parent); \ add_parent(p, (p)->parent); \
} while (0) } while (0)
...@@ -797,11 +799,18 @@ static inline struct task_struct *younger_sibling(struct task_struct *p) ...@@ -797,11 +799,18 @@ static inline struct task_struct *younger_sibling(struct task_struct *p)
#define next_task(p) list_entry((p)->tasks.next, struct task_struct, tasks) #define next_task(p) list_entry((p)->tasks.next, struct task_struct, tasks)
#define prev_task(p) list_entry((p)->tasks.prev, struct task_struct, tasks) #define prev_task(p) list_entry((p)->tasks.prev, struct task_struct, tasks)
#define for_each_task(p) \ #define for_each_process(p) \
for (p = &init_task ; (p = next_task(p)) != &init_task ; ) for (p = &init_task ; (p = next_task(p)) != &init_task ; )
#define for_each_thread(task) \ /*
for (task = next_thread(current) ; task != current ; task = next_thread(task)) * Careful: do_each_thread/while_each_thread is a double loop so
* 'break' will not work as expected - use goto instead.
*/
#define do_each_thread(g, t) \
for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
#define while_each_thread(g, t) \
while ((t = next_thread(t)) != g)
static inline task_t *next_thread(task_t *p) static inline task_t *next_thread(task_t *p)
{ {
......
...@@ -83,13 +83,13 @@ static inline void cap_set_pg(int pgrp, kernel_cap_t *effective, ...@@ -83,13 +83,13 @@ static inline void cap_set_pg(int pgrp, kernel_cap_t *effective,
kernel_cap_t *inheritable, kernel_cap_t *inheritable,
kernel_cap_t *permitted) kernel_cap_t *permitted)
{ {
task_t *target; task_t *g, *target;
for_each_task(target) { do_each_thread(g, target) {
if (target->pgrp != pgrp) if (target->pgrp != pgrp)
continue; continue;
security_ops->capset_set(target, effective, inheritable, permitted); security_ops->capset_set(target, effective, inheritable, permitted);
} } while_each_thread(g, target);
} }
/* /*
...@@ -100,13 +100,13 @@ static inline void cap_set_all(kernel_cap_t *effective, ...@@ -100,13 +100,13 @@ static inline void cap_set_all(kernel_cap_t *effective,
kernel_cap_t *inheritable, kernel_cap_t *inheritable,
kernel_cap_t *permitted) kernel_cap_t *permitted)
{ {
task_t *target; task_t *g, *target;
for_each_task(target) { do_each_thread(g, target) {
if (target == current || target->pid == 1) if (target == current || target->pid == 1)
continue; continue;
security_ops->capset_set(target, effective, inheritable, permitted); security_ops->capset_set(target, effective, inheritable, permitted);
} } while_each_thread(g, target);
} }
/* /*
......
...@@ -115,7 +115,7 @@ int session_of_pgrp(int pgrp) ...@@ -115,7 +115,7 @@ int session_of_pgrp(int pgrp)
fallback = -1; fallback = -1;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { for_each_process(p) {
if (p->session <= 0) if (p->session <= 0)
continue; continue;
if (p->pgrp == pgrp) { if (p->pgrp == pgrp) {
...@@ -141,7 +141,7 @@ static int __will_become_orphaned_pgrp(int pgrp, struct task_struct * ignored_ta ...@@ -141,7 +141,7 @@ static int __will_become_orphaned_pgrp(int pgrp, struct task_struct * ignored_ta
{ {
struct task_struct *p; struct task_struct *p;
for_each_task(p) { for_each_process(p) {
if ((p == ignored_task) || (p->pgrp != pgrp) || if ((p == ignored_task) || (p->pgrp != pgrp) ||
(p->state == TASK_ZOMBIE) || (p->state == TASK_ZOMBIE) ||
(p->parent->pid == 1)) (p->parent->pid == 1))
...@@ -175,7 +175,7 @@ static inline int __has_stopped_jobs(int pgrp) ...@@ -175,7 +175,7 @@ static inline int __has_stopped_jobs(int pgrp)
int retval = 0; int retval = 0;
struct task_struct * p; struct task_struct * p;
for_each_task(p) { for_each_process(p) {
if (p->pgrp != pgrp) if (p->pgrp != pgrp)
continue; continue;
if (p->state != TASK_STOPPED) if (p->state != TASK_STOPPED)
......
...@@ -161,7 +161,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig) ...@@ -161,7 +161,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
static int get_pid(unsigned long flags) static int get_pid(unsigned long flags)
{ {
struct task_struct *p; struct task_struct *g, *p;
int pid; int pid;
if (flags & CLONE_IDLETASK) if (flags & CLONE_IDLETASK)
...@@ -178,7 +178,7 @@ static int get_pid(unsigned long flags) ...@@ -178,7 +178,7 @@ static int get_pid(unsigned long flags)
next_safe = pid_max; next_safe = pid_max;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
repeat: repeat:
for_each_task(p) { do_each_thread(g, p) {
if (p->pid == last_pid || if (p->pid == last_pid ||
p->pgrp == last_pid || p->pgrp == last_pid ||
p->session == last_pid) { p->session == last_pid) {
...@@ -195,7 +195,8 @@ static int get_pid(unsigned long flags) ...@@ -195,7 +195,8 @@ static int get_pid(unsigned long flags)
next_safe = p->pgrp; next_safe = p->pgrp;
if (p->session > last_pid && next_safe > p->session) if (p->session > last_pid && next_safe > p->session)
next_safe = p->session; next_safe = p->session;
} } while_each_thread(g, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
} }
pid = last_pid; pid = last_pid;
......
...@@ -1838,7 +1838,7 @@ char * render_sigset_t(sigset_t *set, char *buffer) ...@@ -1838,7 +1838,7 @@ char * render_sigset_t(sigset_t *set, char *buffer)
void show_state(void) void show_state(void)
{ {
task_t *p; task_t *g, *p;
#if (BITS_PER_LONG == 32) #if (BITS_PER_LONG == 32)
printk("\n" printk("\n"
...@@ -1850,14 +1850,15 @@ void show_state(void) ...@@ -1850,14 +1850,15 @@ void show_state(void)
printk(" task PC stack pid father child younger older\n"); printk(" task PC stack pid father child younger older\n");
#endif #endif
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p) {
/* /*
* reset the NMI-timeout, listing all files on a slow * reset the NMI-timeout, listing all files on a slow
* console might take alot of time: * console might take alot of time:
*/ */
touch_nmi_watchdog(); touch_nmi_watchdog();
show_task(p); show_task(p);
} } while_each_thread(g, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
} }
......
...@@ -938,8 +938,8 @@ int __kill_pg_info(int sig, struct siginfo *info, pid_t pgrp) ...@@ -938,8 +938,8 @@ int __kill_pg_info(int sig, struct siginfo *info, pid_t pgrp)
struct task_struct *p; struct task_struct *p;
retval = -ESRCH; retval = -ESRCH;
for_each_task(p) { for_each_process(p) {
if (p->pgrp == pgrp && thread_group_leader(p)) { if (p->pgrp == pgrp) {
int err = send_sig_info(sig, info, p); int err = send_sig_info(sig, info, p);
if (retval) if (retval)
retval = err; retval = err;
...@@ -976,7 +976,7 @@ kill_sl_info(int sig, struct siginfo *info, pid_t sess) ...@@ -976,7 +976,7 @@ kill_sl_info(int sig, struct siginfo *info, pid_t sess)
retval = -ESRCH; retval = -ESRCH;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { for_each_process(p) {
if (p->leader && p->session == sess) { if (p->leader && p->session == sess) {
int err = send_sig_info(sig, info, p); int err = send_sig_info(sig, info, p);
if (retval) if (retval)
...@@ -1020,8 +1020,8 @@ static int kill_something_info(int sig, struct siginfo *info, int pid) ...@@ -1020,8 +1020,8 @@ static int kill_something_info(int sig, struct siginfo *info, int pid)
struct task_struct * p; struct task_struct * p;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { for_each_process(p) {
if (p->pid > 1 && p != current && thread_group_leader(p)) { if (p->pid > 1 && p != current) {
int err = send_sig_info(sig, info, p); int err = send_sig_info(sig, info, p);
++count; ++count;
if (err != -EPERM) if (err != -EPERM)
......
...@@ -204,14 +204,14 @@ void refrigerator(unsigned long flag) ...@@ -204,14 +204,14 @@ void refrigerator(unsigned long flag)
int freeze_processes(void) int freeze_processes(void)
{ {
int todo, start_time; int todo, start_time;
struct task_struct *p; struct task_struct *g, *p;
printk( "Stopping tasks: " ); printk( "Stopping tasks: " );
start_time = jiffies; start_time = jiffies;
do { do {
todo = 0; todo = 0;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p) {
unsigned long flags; unsigned long flags;
INTERESTING(p); INTERESTING(p);
if (p->flags & PF_FROZEN) if (p->flags & PF_FROZEN)
...@@ -224,7 +224,7 @@ int freeze_processes(void) ...@@ -224,7 +224,7 @@ int freeze_processes(void)
signal_wake_up(p); signal_wake_up(p);
spin_unlock_irqrestore(&p->sigmask_lock, flags); spin_unlock_irqrestore(&p->sigmask_lock, flags);
todo++; todo++;
} } while_each_thread(g, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
yield(); yield();
if (time_after(jiffies, start_time + TIMEOUT)) { if (time_after(jiffies, start_time + TIMEOUT)) {
...@@ -240,18 +240,19 @@ int freeze_processes(void) ...@@ -240,18 +240,19 @@ int freeze_processes(void)
void thaw_processes(void) void thaw_processes(void)
{ {
struct task_struct *p; struct task_struct *g, *p;
printk( "Restarting tasks..." ); printk( "Restarting tasks..." );
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p) {
INTERESTING(p); INTERESTING(p);
if (p->flags & PF_FROZEN) p->flags &= ~PF_FROZEN; if (p->flags & PF_FROZEN) p->flags &= ~PF_FROZEN;
else else
printk(KERN_INFO " Strange, %s not stopped\n", p->comm ); printk(KERN_INFO " Strange, %s not stopped\n", p->comm );
wake_up_process(p); wake_up_process(p);
} } while_each_thread(g, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
printk( " done\n" ); printk( " done\n" );
MDELAY(500); MDELAY(500);
......
...@@ -227,7 +227,7 @@ static int proc_sel(struct task_struct *p, int which, int who) ...@@ -227,7 +227,7 @@ static int proc_sel(struct task_struct *p, int which, int who)
asmlinkage long sys_setpriority(int which, int who, int niceval) asmlinkage long sys_setpriority(int which, int who, int niceval)
{ {
struct task_struct *p; struct task_struct *g, *p;
int error; int error;
if (which > 2 || which < 0) if (which > 2 || which < 0)
...@@ -241,7 +241,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval) ...@@ -241,7 +241,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
niceval = 19; niceval = 19;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p) {
int no_nice; int no_nice;
if (!proc_sel(p, which, who)) if (!proc_sel(p, which, who))
continue; continue;
...@@ -262,8 +262,8 @@ asmlinkage long sys_setpriority(int which, int who, int niceval) ...@@ -262,8 +262,8 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
continue; continue;
} }
set_user_nice(p, niceval); set_user_nice(p, niceval);
} while_each_thread(g, p);
}
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
return error; return error;
...@@ -277,21 +277,21 @@ asmlinkage long sys_setpriority(int which, int who, int niceval) ...@@ -277,21 +277,21 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
*/ */
asmlinkage long sys_getpriority(int which, int who) asmlinkage long sys_getpriority(int which, int who)
{ {
struct task_struct *p; struct task_struct *g, *p;
long retval = -ESRCH; long retval = -ESRCH;
if (which > 2 || which < 0) if (which > 2 || which < 0)
return -EINVAL; return -EINVAL;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task (p) { do_each_thread(g, p) {
long niceval; long niceval;
if (!proc_sel(p, which, who)) if (!proc_sel(p, which, who))
continue; continue;
niceval = 20 - task_nice(p); niceval = 20 - task_nice(p);
if (niceval > retval) if (niceval > retval)
retval = niceval; retval = niceval;
} } while_each_thread(g, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
return retval; return retval;
...@@ -882,12 +882,12 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) ...@@ -882,12 +882,12 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
if (p->leader) if (p->leader)
goto out; goto out;
if (pgid != pid) { if (pgid != pid) {
struct task_struct * tmp; struct task_struct *g, *tmp;
for_each_task (tmp) { do_each_thread(g, tmp) {
if (tmp->pgrp == pgid && if (tmp->pgrp == pgid &&
tmp->session == current->session) tmp->session == current->session)
goto ok_pgid; goto ok_pgid;
} } while_each_thread(g, tmp);
goto out; goto out;
} }
...@@ -956,14 +956,14 @@ asmlinkage long sys_getsid(pid_t pid) ...@@ -956,14 +956,14 @@ asmlinkage long sys_getsid(pid_t pid)
asmlinkage long sys_setsid(void) asmlinkage long sys_setsid(void)
{ {
struct task_struct * p; struct task_struct *g, *p;
int err = -EPERM; int err = -EPERM;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p)
if (p->pgrp == current->pid) if (p->pgrp == current->pid)
goto out; goto out;
} while_each_thread(g, p);
current->leader = 1; current->leader = 1;
current->session = current->pgrp = current->pid; current->session = current->pgrp = current->pid;
......
...@@ -116,10 +116,10 @@ static int badness(struct task_struct *p) ...@@ -116,10 +116,10 @@ static int badness(struct task_struct *p)
static struct task_struct * select_bad_process(void) static struct task_struct * select_bad_process(void)
{ {
int maxpoints = 0; int maxpoints = 0;
struct task_struct *p = NULL; struct task_struct *g, *p;
struct task_struct *chosen = NULL; struct task_struct *chosen = NULL;
for_each_task(p) { do_each_thread(g, p)
if (p->pid) { if (p->pid) {
int points = badness(p); int points = badness(p);
if (points > maxpoints) { if (points > maxpoints) {
...@@ -127,7 +127,7 @@ static struct task_struct * select_bad_process(void) ...@@ -127,7 +127,7 @@ static struct task_struct * select_bad_process(void)
maxpoints = points; maxpoints = points;
} }
} }
} while_each_thread(g, p);
return chosen; return chosen;
} }
...@@ -166,7 +166,7 @@ void oom_kill_task(struct task_struct *p) ...@@ -166,7 +166,7 @@ void oom_kill_task(struct task_struct *p)
*/ */
static void oom_kill(void) static void oom_kill(void)
{ {
struct task_struct *p, *q; struct task_struct *g, *p, *q;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
p = select_bad_process(); p = select_bad_process();
...@@ -176,9 +176,11 @@ static void oom_kill(void) ...@@ -176,9 +176,11 @@ static void oom_kill(void)
panic("Out of memory and no killable processes...\n"); panic("Out of memory and no killable processes...\n");
/* kill all processes that share the ->mm (i.e. all threads) */ /* kill all processes that share the ->mm (i.e. all threads) */
for_each_task(q) { do_each_thread(g, q)
if(q->mm == p->mm) oom_kill_task(q); if (q->mm == p->mm)
} oom_kill_task(q);
while_each_thread(g, q);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
/* /*
......
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
static int static int
match_comm(const struct sk_buff *skb, const char *comm) match_comm(const struct sk_buff *skb, const char *comm)
{ {
struct task_struct *p; struct task_struct *g, *p;
struct files_struct *files; struct files_struct *files;
int i; int i;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p) {
if(strncmp(p->comm, comm, sizeof(p->comm))) if(strncmp(p->comm, comm, sizeof(p->comm)))
continue; continue;
...@@ -38,7 +38,7 @@ match_comm(const struct sk_buff *skb, const char *comm) ...@@ -38,7 +38,7 @@ match_comm(const struct sk_buff *skb, const char *comm)
read_unlock(&files->file_lock); read_unlock(&files->file_lock);
} }
task_unlock(p); task_unlock(p);
} } while_each_thread(g, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
return 0; return 0;
} }
...@@ -77,12 +77,12 @@ match_pid(const struct sk_buff *skb, pid_t pid) ...@@ -77,12 +77,12 @@ match_pid(const struct sk_buff *skb, pid_t pid)
static int static int
match_sid(const struct sk_buff *skb, pid_t sid) match_sid(const struct sk_buff *skb, pid_t sid)
{ {
struct task_struct *p; struct task_struct *g, *p;
struct file *file = skb->sk->socket->file; struct file *file = skb->sk->socket->file;
int i, found=0; int i, found=0;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p) {
struct files_struct *files; struct files_struct *files;
if (p->session != sid) if (p->session != sid)
continue; continue;
...@@ -100,9 +100,10 @@ match_sid(const struct sk_buff *skb, pid_t sid) ...@@ -100,9 +100,10 @@ match_sid(const struct sk_buff *skb, pid_t sid)
read_unlock(&files->file_lock); read_unlock(&files->file_lock);
} }
task_unlock(p); task_unlock(p);
if(found) if (found)
break; goto out;
} } while_each_thread(g, p);
out:
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
return found; return found;
......
...@@ -49,12 +49,12 @@ match_pid(const struct sk_buff *skb, pid_t pid) ...@@ -49,12 +49,12 @@ match_pid(const struct sk_buff *skb, pid_t pid)
static int static int
match_sid(const struct sk_buff *skb, pid_t sid) match_sid(const struct sk_buff *skb, pid_t sid)
{ {
struct task_struct *p; struct task_struct *g, *p;
struct file *file = skb->sk->socket->file; struct file *file = skb->sk->socket->file;
int i, found=0; int i, found=0;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_task(p) { do_each_thread(g, p) {
struct files_struct *files; struct files_struct *files;
if (p->session != sid) if (p->session != sid)
continue; continue;
...@@ -72,9 +72,10 @@ match_sid(const struct sk_buff *skb, pid_t sid) ...@@ -72,9 +72,10 @@ match_sid(const struct sk_buff *skb, pid_t sid)
read_unlock(&files->file_lock); read_unlock(&files->file_lock);
} }
task_unlock(p); task_unlock(p);
if(found) if (found)
break; goto out;
} } while_each_thread(g, p);
out:
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
return found; return found;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment