This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / kernel / vserver / signal.c
1 /*
2  *  linux/kernel/vserver/signal.c
3  *
4  *  Virtual Server: Signal Support
5  *
6  *  Copyright (C) 2003-2004  Herbert Pƶtzl
7  *
8  *  V0.01  broken out from vcontext V0.05
9  *
10  */
11
12 #include <linux/config.h>
13 #include <linux/sched.h>
14
15 #include <asm/errno.h>
16 #include <asm/uaccess.h>
17
18 #include <linux/vinline.h>
19 #include <linux/vserver/signal.h>
20
21
22 int vc_ctx_kill(uint32_t id, void __user *data)
23 {
24         int retval, count=0;
25         struct vcmd_ctx_kill_v0 vc_data;
26         struct siginfo info;
27         struct task_struct *p;
28         struct vx_info *vxi;
29
30         if (!vx_check(0, VX_ADMIN))
31                 return -ENOSYS;
32         if (copy_from_user (&vc_data, data, sizeof(vc_data)))
33                 return -EFAULT;
34         
35         info.si_signo = vc_data.sig;
36         info.si_errno = 0;
37         info.si_code = SI_USER;
38         info.si_pid = current->pid;
39         info.si_uid = current->uid;
40
41         vxi = find_vx_info(id);
42         if (!vxi)
43                 return -ESRCH;
44
45         retval = -ESRCH;
46         read_lock(&tasklist_lock);
47         switch (vc_data.pid) {
48         case -1:
49         case  0:
50                 for_each_process(p) {
51                         int err = 0;
52
53                         if (vx_task_xid(p) != id || p->pid <= 1 ||
54                                 (vc_data.pid && vxi->vx_initpid == p->pid) ||
55                                 !thread_group_leader(p))
56                                 continue;
57
58                         err = send_sig_info(vc_data.sig, &info, p);
59                         ++count;
60                         if (err != -EPERM)
61                                 retval = err;
62                 }
63                 break;
64                 
65         default:
66         p = find_task_by_pid(vc_data.pid);
67                 if (p) {
68                         if (!thread_group_leader(p)) {
69                                 struct task_struct *tg;
70                         
71                                 tg = find_task_by_pid(p->tgid);
72                                 if (tg)
73                                         p = tg;
74                         }
75                         if ((id == -1) || (vx_task_xid(p) == id))
76                                 retval = send_sig_info(vc_data.sig, &info, p);
77                 }
78                 break;
79         }
80         read_unlock(&tasklist_lock);
81         put_vx_info(vxi);
82         return retval;
83 }
84
85