public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Introduce ActivePid: in /proc/self/status (v2, was Vpid:)
@ 2011-06-15 14:55 Greg Kurz
  2011-06-15 18:46 ` Oleg Nesterov
                   ` (2 more replies)
  0 siblings, 3 replies; 34+ messages in thread
From: Greg Kurz @ 2011-06-15 14:55 UTC (permalink / raw)
  To: akpm; +Cc: containers, linux-kernel, serge, daniel.lezcano, ebiederm, oleg,
	xemul

Since pid namespaces were introduced, there's a recurring demand: how one
can correlate a pid from a child pid ns with a pid from a parent pid ns ?
The need arises in the LXC community when one wants to send a signal from
the host (aka. init_pid_ns context) to a container process for which one
only knows the pid inside the container.

In the future, this should be achievable thanks to Eric Biederman's setns()
syscall but there's still some work to be done to support pid namespaces:

https://lkml.org/lkml/2011/5/21/162

As stated by Serge Hallyn in:

http://sourceforge.net/mailarchive/message.php?msg_id=27424447

"There is nothing that gives you a 100% guaranteed correct race-free
correspondence right now.  You can look under /proc/<pid>/root/proc/ to
see the pids valid in the container, and you can relate output of
lxc-ps --forest to ps --forest output.  But nothing under /proc that I
know of tells you "this task is the same as that task".  You can't
even look at /proc/<pid> inode numbers since they are different
filesystems for each proc mount."

This patch adds a single line to /proc/self/status. Provided one has kept
track of its container tasks (with a cgroup like liblxc does for example),
he may correlate global pids and container pids. This is still racy but
definitely easier than what we have today.

ChangeLog:
	v2: - changed Vpid: to ActivePid:
	    - lock ->sighand before calling task_active_pid_ns()

Signed-off-by: Greg Kurz <gkurz@fr.ibm.com>
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
---

 fs/proc/array.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 5e4f776..5f796d9 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -165,7 +165,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
 	int g;
 	struct fdtable *fdt = NULL;
 	const struct cred *cred;
-	pid_t ppid, tpid;
+	pid_t ppid, tpid, actpid;
+	struct sighand_struct *sighand;
 
 	rcu_read_lock();
 	ppid = pid_alive(p) ?
@@ -176,6 +177,17 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
 		if (tracer)
 			tpid = task_pid_nr_ns(tracer, ns);
 	}
+	actpid = 0;
+	sighand = rcu_dereference(p->sighand);
+	if (sighand) {
+		struct pid_namespace *pid_ns;
+		unsigned long flags;
+		spin_lock_irqsave(&sighand->siglock, flags);
+		pid_ns = task_active_pid_ns(p);
+		if (pid_ns)
+			actpid = task_pid_nr_ns(p, pid_ns);
+		spin_unlock_irqrestore(&sighand->siglock, flags);
+	}
 	cred = get_task_cred(p);
 	seq_printf(m,
 		"State:\t%s\n"
@@ -183,12 +195,13 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
 		"Pid:\t%d\n"
 		"PPid:\t%d\n"
 		"TracerPid:\t%d\n"
+		"ActivePid:\t%d\n"
 		"Uid:\t%d\t%d\t%d\t%d\n"
 		"Gid:\t%d\t%d\t%d\t%d\n",
 		get_task_state(p),
 		task_tgid_nr_ns(p, ns),
 		pid_nr_ns(pid, ns),
-		ppid, tpid,
+		ppid, tpid, actpid,
 		cred->uid, cred->euid, cred->suid, cred->fsuid,
 		cred->gid, cred->egid, cred->sgid, cred->fsgid);
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2011-06-23 14:38 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-15 14:55 [PATCH] Introduce ActivePid: in /proc/self/status (v2, was Vpid:) Greg Kurz
2011-06-15 18:46 ` Oleg Nesterov
2011-06-15 19:08   ` Eric W. Biederman
2011-06-16 11:01   ` Greg Kurz
2011-06-16 12:35     ` Louis Rilling
2011-06-16 13:00       ` Greg Kurz
2011-06-16 13:18         ` Oleg Nesterov
2011-06-16 13:25         ` Louis Rilling
2011-06-16 14:51           ` Oleg Nesterov
2011-06-16 15:08             ` Louis Rilling
2011-06-16 15:01           ` Greg Kurz
2011-06-16 15:27             ` Louis Rilling
2011-06-16 12:42     ` Oleg Nesterov
2011-06-15 19:03 ` Oleg Nesterov
2011-06-16 11:19   ` Greg Kurz
2011-06-16 12:25     ` Cedric Le Goater
2011-06-16 13:06       ` Oleg Nesterov
2011-06-16 14:25         ` Cedric Le Goater
2011-06-16 15:22           ` Eric W. Biederman
2011-06-16 16:22             ` Oleg Nesterov
2011-06-16 15:07       ` Eric W. Biederman
2011-06-16 15:33         ` Greg Kurz
2011-06-16 16:12           ` Oleg Nesterov
2011-06-16 12:52     ` Oleg Nesterov
2011-06-16 17:54 ` Bryan Donlan
2011-06-20 11:45   ` Greg Kurz
2011-06-20 17:37     ` Bryan Donlan
2011-06-20 22:44       ` Eric W. Biederman
2011-06-22 15:29         ` Greg Kurz
2011-06-23  0:39           ` Eric W. Biederman
2011-06-23 13:43             ` Greg Kurz
2011-06-23 14:37               ` Serge Hallyn
2011-06-22 15:00       ` Greg Kurz
2011-06-22 16:56         ` Bryan Donlan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox