[13/21] ns: Use alternative name in set_ns_hookups() if need

Submitted by Kirill Tkhai on May 23, 2017, 12:40 p.m.

Details

Message ID 149554321907.12386.9500684832386055627.stgit@localhost.localdomain
State New
Series "Add /proc/[pid]/ns/pid_for_children ns support (and fixes)"
Headers show

Commit Message

Kirill Tkhai May 23, 2017, 12:40 p.m.
Account the fact, that ns may be found by alternative
name, and use it if so.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/include/namespaces.h |    1 +
 criu/namespaces.c         |    3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 1c406b39e..1f5783317 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -101,6 +101,7 @@  struct ns_id {
 	unsigned int kid;
 	unsigned int id;
 	pid_t ns_pid;
+	bool alternative;
 	struct ns_desc *nd;
 	struct ns_id *parent;
 	struct list_head children;
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 1a03caa89..94f9140cc 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -443,6 +443,7 @@  static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd
 	nsid->ns_populated = true;
 	INIT_LIST_HEAD(&nsid->children);
 	INIT_LIST_HEAD(&nsid->siblings);
+	nsid->alternative = alternative;
 	nsid_add(nsid, nd, ns_next_id++, pid);
 	BUG_ON(nsid->id == UINT_MAX);
 
@@ -804,7 +805,7 @@  static int set_ns_hookups(struct ns_id *ns)
 	struct ns_id *u_ns;
 	int fd, ret = -1;
 
-	fd = open_proc(ns->ns_pid, "ns/%s", nd->str);
+	fd = open_proc(ns->ns_pid, "ns/%s", !ns->alternative ? nd->str : nd->alt_str);
 	if (fd < 0) {
 		pr_perror("Can't open %s, pid %d", nd->str, ns->ns_pid);
 		return -1;