4 #include "vserver/base.h"
5 #include "vserver/context.h"
6 #include "vserver/debug.h"
7 #include <linux/pid_namespace.h>
10 /* pid faking stuff */
13 #define vx_info_map_pid(v,p) \
14 __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
15 #define vx_info_map_tgid(v,p) vx_info_map_pid(v,p)
16 #define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
17 #define vx_map_tgid(p) vx_map_pid(p)
19 static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
20 const char *func, const char *file, int line)
22 if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
23 vxfprintk(VXD_CBIT(cvirt, 2),
24 "vx_map_tgid: %p/%llx: %d -> %d",
25 vxi, (long long)vxi->vx_flags, pid,
26 (pid && pid == vxi->vx_initpid)?1:pid,
30 if (pid == vxi->vx_initpid)
36 #define vx_info_rmap_pid(v,p) \
37 __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
38 #define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
39 #define vx_rmap_tgid(p) vx_rmap_pid(p)
41 static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
42 const char *func, const char *file, int line)
44 if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
45 vxfprintk(VXD_CBIT(cvirt, 2),
46 "vx_rmap_tgid: %p/%llx: %d -> %d",
47 vxi, (long long)vxi->vx_flags, pid,
48 (pid == 1)?vxi->vx_initpid:pid,
50 if ((pid == 1) && vxi->vx_initpid)
51 return vxi->vx_initpid;
52 if (pid == vxi->vx_initpid)
59 #define VXF_FAKE_INIT (VXF_INFO_INIT|VXF_STATE_INIT)
62 int vx_proc_task_visible(struct task_struct *task)
64 if ((task->pid == 1) &&
65 !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
66 /* show a blend through init */
68 if (vx_check(vx_task_xid(task), VS_WATCH|VS_IDENT))
76 struct task_struct *vx_find_proc_task_by_pid(int pid)
78 struct task_struct *task = find_task_by_real_pid(pid);
80 if (task && !vx_proc_task_visible(task)) {
81 vxdprintk(VXD_CBIT(misc, 6),
82 "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
83 task, task->xid, task->pid,
84 current, current->xid, current->pid);
91 struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
93 struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
95 if (task && !vx_proc_task_visible(task)) {
96 vxdprintk(VXD_CBIT(misc, 6),
97 "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
98 task, task->xid, task->pid,
99 current, current->xid, current->pid);
100 put_task_struct(task);
108 struct task_struct *vx_child_reaper(struct task_struct *p)
110 struct vx_info *vxi = p->vx_info;
111 struct task_struct *reaper = child_reaper(p);
116 BUG_ON(!p->vx_info->vx_reaper);
118 /* child reaper for the guest reaper */
119 if (vxi->vx_reaper == p)
122 reaper = vxi->vx_reaper;
124 vxdprintk(VXD_CBIT(xid, 7),
125 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
126 p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
132 #warning duplicate inclusion