vserver 1.9.5.x5
[linux-2.6.git] / kernel / vserver / signal.c
index 200eba8..ae4d11f 100644 (file)
@@ -3,7 +3,7 @@
  *
  *  Virtual Server: Signal Support
  *
- *  Copyright (C) 2003-2004  Herbert Pötzl
+ *  Copyright (C) 2003-2005  Herbert Pötzl
  *
  *  V0.01  broken out from vcontext V0.05
  *
@@ -15,7 +15,7 @@
 #include <asm/errno.h>
 #include <asm/uaccess.h>
 
-#include <linux/vinline.h>
+#include <linux/vs_context.h>
 #include <linux/vserver/signal.h>
 
 
@@ -31,7 +31,7 @@ int vc_ctx_kill(uint32_t id, void __user *data)
                return -ENOSYS;
        if (copy_from_user (&vc_data, data, sizeof(vc_data)))
                return -EFAULT;
-       
+
        info.si_signo = vc_data.sig;
        info.si_errno = 0;
        info.si_code = SI_USER;
@@ -45,8 +45,9 @@ int vc_ctx_kill(uint32_t id, void __user *data)
        retval = -ESRCH;
        read_lock(&tasklist_lock);
        switch (vc_data.pid) {
-       case -1:
        case  0:
+               info.si_code = SI_KERNEL;
+       case -1:
                for_each_process(p) {
                        int err = 0;
 
@@ -61,14 +62,20 @@ int vc_ctx_kill(uint32_t id, void __user *data)
                                retval = err;
                }
                break;
-               
+
+       case 1:
+               if (vxi->vx_initpid) {
+                       vc_data.pid = vxi->vx_initpid;
+                       info.si_code = SI_KERNEL;
+               }
+               /* fallthrough */
        default:
-       p = find_task_by_pid(vc_data.pid);
+               p = find_task_by_real_pid(vc_data.pid);
                if (p) {
                        if (!thread_group_leader(p)) {
                                struct task_struct *tg;
-                       
-                               tg = find_task_by_pid(p->tgid);
+
+                               tg = find_task_by_real_pid(p->tgid);
                                if (tg)
                                        p = tg;
                        }
@@ -83,3 +90,44 @@ int vc_ctx_kill(uint32_t id, void __user *data)
 }
 
 
+static int __wait_exit(struct vx_info *vxi)
+{
+       DECLARE_WAITQUEUE(wait, current);
+       int ret = 0;
+
+       add_wait_queue(&vxi->vx_exit, &wait);
+       set_current_state(TASK_INTERRUPTIBLE);
+
+wait:
+       if (vx_info_state(vxi, VXS_DEFUNCT))
+               goto out;
+       if (signal_pending(current)) {
+               ret = -ERESTARTSYS;
+               goto out;
+       }
+       schedule();
+       goto wait;
+
+out:
+       set_current_state(TASK_RUNNING);
+       remove_wait_queue(&vxi->vx_exit, &wait);
+       return ret;
+}
+
+
+
+int vc_wait_exit(uint32_t id, void __user *data)
+{
+//     struct vcmd_wait_exit_v0 vc_data;
+       struct vx_info *vxi;
+       int ret;
+
+       vxi = locate_vx_info(id);
+       if (!vxi)
+               return -ESRCH;
+
+       ret = __wait_exit(vxi);
+       put_vx_info(vxi);
+       return ret;
+}
+