static inline int task_valid(struct task_struct *tsk)
{
- struct task_struct *p;
+ struct task_struct *g, *p;
int ret = 0;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p)
if ((p == tsk) && (p->sig)) {
ret = 1;
- break;
+ goto out;
}
- }
+ while_each_thread(g, p);
+out:
read_unlock(&tasklist_lock);
return ret;
}
{
struct task_struct *p;
- for_each_task(p) {
+ for_each_process(p) {
if (p->mm && p->pid != 1)
/* Not swapper, init nor kernel thread */
force_sig(sig, p);
}
read_lock(&tasklist_lock);
- for_each_task(p) {
+ for_each_process(p) {
if ((tty->session > 0) && (p->session == tty->session) &&
p->leader) {
send_sig(SIGHUP,p,1);
tty->pgrp = -1;
read_lock(&tasklist_lock);
- for_each_task(p)
+ for_each_process(p)
if (p->session == current->session)
p->tty = NULL;
read_unlock(&tasklist_lock);
struct task_struct *p;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ for_each_process(p) {
if (p->tty == tty || (o_tty && p->tty == o_tty))
p->tty = NULL;
}
struct task_struct *p;
read_lock(&tasklist_lock);
- for_each_task(p)
+ for_each_process(p)
if (p->tty == tty)
p->tty = NULL;
read_unlock(&tasklist_lock);
if (tty->driver.flush_buffer)
tty->driver.flush_buffer(tty);
read_lock(&tasklist_lock);
- for_each_task(p) {
+ for_each_process(p) {
if ((p->tty == tty) ||
((session > 0) && (p->session == session))) {
printk(KERN_NOTICE "SAK: killed process %d"
send_sigio_to_task(p, fown, fd, band);
goto out_unlock_task;
}
- for_each_task(p) {
+ for_each_process(p) {
int match = p->pid;
if (pid < 0)
match = -p->pgrp;
send_sigurg_to_task(p, fown);
goto out_unlock_task;
}
- for_each_task(p) {
+ for_each_process(p) {
int match = p->pid;
if (pid < 0)
match = -p->pgrp;
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;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p) {
task_lock(p);
fs = p->fs;
if (fs) {
put_fs_struct(fs);
} else
task_unlock(p);
- }
+ } while_each_thread(g, p);
read_unlock(&tasklist_lock);
}
{
struct vfsmount *mnt;
struct namespace *namespace;
- struct task_struct *p;
+ struct task_struct *g, *p;
mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
if (IS_ERR(mnt))
init_task.namespace = namespace;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p) {
get_namespace(namespace);
p->namespace = namespace;
- }
+ } while_each_thread(g, p);
read_unlock(&tasklist_lock);
set_fs_pwd(current->fs, namespace->root, namespace->root->mnt_root);
index--;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ for_each_process(p) {
int pid = p->pid;
if (!pid)
continue;
* Fixup the root inode's nlink value
*/
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);
s->s_root = d_alloc_root(root_inode);
if (!s->s_root)
#define remove_parent(p) list_del_init(&(p)->sibling)
#define add_parent(p, parent) list_add_tail(&(p)->sibling,&(parent)->children)
-#define REMOVE_LINKS(p) do { \
- list_del_init(&(p)->tasks); \
- remove_parent(p); \
+#define REMOVE_LINKS(p) do { \
+ if (thread_group_leader(p)) \
+ list_del_init(&(p)->tasks); \
+ remove_parent(p); \
} while (0)
-#define SET_LINKS(p) do { \
- list_add_tail(&(p)->tasks,&init_task.tasks); \
- add_parent(p, (p)->parent); \
+#define SET_LINKS(p) do { \
+ if (thread_group_leader(p)) \
+ list_add_tail(&(p)->tasks,&init_task.tasks); \
+ add_parent(p, (p)->parent); \
} while (0)
static inline struct task_struct *eldest_child(struct task_struct *p)
#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 for_each_task(p) \
+#define for_each_process(p) \
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)
{
kernel_cap_t *inheritable,
kernel_cap_t *permitted)
{
- task_t *target;
+ task_t *g, *target;
- for_each_task(target) {
+ do_each_thread(g, target) {
if (target->pgrp != pgrp)
continue;
security_ops->capset_set(target, effective, inheritable, permitted);
- }
+ } while_each_thread(g, target);
}
/*
kernel_cap_t *inheritable,
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)
continue;
security_ops->capset_set(target, effective, inheritable, permitted);
- }
+ } while_each_thread(g, target);
}
/*
fallback = -1;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ for_each_process(p) {
if (p->session <= 0)
continue;
if (p->pgrp == pgrp) {
{
struct task_struct *p;
- for_each_task(p) {
+ for_each_process(p) {
if ((p == ignored_task) || (p->pgrp != pgrp) ||
(p->state == TASK_ZOMBIE) ||
(p->parent->pid == 1))
int retval = 0;
struct task_struct * p;
- for_each_task(p) {
+ for_each_process(p) {
if (p->pgrp != pgrp)
continue;
if (p->state != TASK_STOPPED)
static int get_pid(unsigned long flags)
{
- struct task_struct *p;
+ struct task_struct *g, *p;
int pid;
if (flags & CLONE_IDLETASK)
next_safe = pid_max;
read_lock(&tasklist_lock);
repeat:
- for_each_task(p) {
+ do_each_thread(g, p) {
if (p->pid == last_pid ||
p->pgrp == last_pid ||
p->session == last_pid) {
next_safe = p->pgrp;
if (p->session > last_pid && next_safe > p->session)
next_safe = p->session;
- }
+ } while_each_thread(g, p);
+
read_unlock(&tasklist_lock);
}
pid = last_pid;
void show_state(void)
{
- task_t *p;
+ task_t *g, *p;
#if (BITS_PER_LONG == 32)
printk("\n"
printk(" task PC stack pid father child younger older\n");
#endif
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p) {
/*
* reset the NMI-timeout, listing all files on a slow
* console might take alot of time:
*/
touch_nmi_watchdog();
show_task(p);
- }
+ } while_each_thread(g, p);
+
read_unlock(&tasklist_lock);
}
struct task_struct *p;
retval = -ESRCH;
- for_each_task(p) {
- if (p->pgrp == pgrp && thread_group_leader(p)) {
+ for_each_process(p) {
+ if (p->pgrp == pgrp) {
int err = send_sig_info(sig, info, p);
if (retval)
retval = err;
retval = -ESRCH;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ for_each_process(p) {
if (p->leader && p->session == sess) {
int err = send_sig_info(sig, info, p);
if (retval)
struct task_struct * p;
read_lock(&tasklist_lock);
- for_each_task(p) {
- if (p->pid > 1 && p != current && thread_group_leader(p)) {
+ for_each_process(p) {
+ if (p->pid > 1 && p != current) {
int err = send_sig_info(sig, info, p);
++count;
if (err != -EPERM)
int freeze_processes(void)
{
int todo, start_time;
- struct task_struct *p;
+ struct task_struct *g, *p;
printk( "Stopping tasks: " );
start_time = jiffies;
do {
todo = 0;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p) {
unsigned long flags;
INTERESTING(p);
if (p->flags & PF_FROZEN)
signal_wake_up(p);
spin_unlock_irqrestore(&p->sigmask_lock, flags);
todo++;
- }
+ } while_each_thread(g, p);
read_unlock(&tasklist_lock);
yield();
if (time_after(jiffies, start_time + TIMEOUT)) {
void thaw_processes(void)
{
- struct task_struct *p;
+ struct task_struct *g, *p;
printk( "Restarting tasks..." );
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p) {
INTERESTING(p);
if (p->flags & PF_FROZEN) p->flags &= ~PF_FROZEN;
else
printk(KERN_INFO " Strange, %s not stopped\n", p->comm );
wake_up_process(p);
- }
+ } while_each_thread(g, p);
+
read_unlock(&tasklist_lock);
printk( " done\n" );
MDELAY(500);
asmlinkage long sys_setpriority(int which, int who, int niceval)
{
- struct task_struct *p;
+ struct task_struct *g, *p;
int error;
if (which > 2 || which < 0)
niceval = 19;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p) {
int no_nice;
if (!proc_sel(p, which, who))
continue;
continue;
}
set_user_nice(p, niceval);
+ } while_each_thread(g, p);
- }
read_unlock(&tasklist_lock);
return error;
*/
asmlinkage long sys_getpriority(int which, int who)
{
- struct task_struct *p;
+ struct task_struct *g, *p;
long retval = -ESRCH;
if (which > 2 || which < 0)
return -EINVAL;
read_lock(&tasklist_lock);
- for_each_task (p) {
+ do_each_thread(g, p) {
long niceval;
if (!proc_sel(p, which, who))
continue;
niceval = 20 - task_nice(p);
if (niceval > retval)
retval = niceval;
- }
+ } while_each_thread(g, p);
read_unlock(&tasklist_lock);
return retval;
if (p->leader)
goto out;
if (pgid != pid) {
- struct task_struct * tmp;
- for_each_task (tmp) {
+ struct task_struct *g, *tmp;
+ do_each_thread(g, tmp) {
if (tmp->pgrp == pgid &&
tmp->session == current->session)
goto ok_pgid;
- }
+ } while_each_thread(g, tmp);
goto out;
}
asmlinkage long sys_setsid(void)
{
- struct task_struct * p;
+ struct task_struct *g, *p;
int err = -EPERM;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p)
if (p->pgrp == current->pid)
goto out;
- }
+ while_each_thread(g, p);
current->leader = 1;
current->session = current->pgrp = current->pid;
static struct task_struct * select_bad_process(void)
{
int maxpoints = 0;
- struct task_struct *p = NULL;
+ struct task_struct *g, *p;
struct task_struct *chosen = NULL;
- for_each_task(p) {
+ do_each_thread(g, p)
if (p->pid) {
int points = badness(p);
if (points > maxpoints) {
maxpoints = points;
}
}
- }
+ while_each_thread(g, p);
return chosen;
}
*/
static void oom_kill(void)
{
- struct task_struct *p, *q;
+ struct task_struct *g, *p, *q;
read_lock(&tasklist_lock);
p = select_bad_process();
panic("Out of memory and no killable processes...\n");
/* kill all processes that share the ->mm (i.e. all threads) */
- for_each_task(q) {
- if(q->mm == p->mm) oom_kill_task(q);
- }
+ do_each_thread(g, q)
+ if (q->mm == p->mm)
+ oom_kill_task(q);
+ while_each_thread(g, q);
+
read_unlock(&tasklist_lock);
/*
static int
match_comm(const struct sk_buff *skb, const char *comm)
{
- struct task_struct *p;
+ struct task_struct *g, *p;
struct files_struct *files;
int i;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p) {
if(strncmp(p->comm, comm, sizeof(p->comm)))
continue;
read_unlock(&files->file_lock);
}
task_unlock(p);
- }
+ } while_each_thread(g, p);
read_unlock(&tasklist_lock);
return 0;
}
static int
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;
int i, found=0;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p) {
struct files_struct *files;
if (p->session != sid)
continue;
read_unlock(&files->file_lock);
}
task_unlock(p);
- if(found)
- break;
- }
+ if (found)
+ goto out;
+ } while_each_thread(g, p);
+out:
read_unlock(&tasklist_lock);
return found;
static int
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;
int i, found=0;
read_lock(&tasklist_lock);
- for_each_task(p) {
+ do_each_thread(g, p) {
struct files_struct *files;
if (p->session != sid)
continue;
read_unlock(&files->file_lock);
}
task_unlock(p);
- if(found)
- break;
- }
+ if (found)
+ goto out;
+ } while_each_thread(g, p);
+out:
read_unlock(&tasklist_lock);
return found;