From e63f8c20e94fdb79c4d490caab88a812ef13bc15 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Mon, 30 Sep 2013 17:16:47 +0400 Subject: [PATCH] uts: don't use global fdset for dumping namespace We are going to replace pid on id in names of image files. The id is uniq for each namespace, so it's more convient, if image files are opened per namespace. Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- include/uts_ns.h | 2 +- namespaces.c | 2 +- uts_ns.c | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/uts_ns.h b/include/uts_ns.h index 792d43bf7..791992377 100644 --- a/include/uts_ns.h +++ b/include/uts_ns.h @@ -3,7 +3,7 @@ #include "crtools.h" -int dump_uts_ns(int ns_pid, struct cr_fdset *fdset); +int dump_uts_ns(int ns_pid, int ns_id); int prepare_utsns(int pid); extern struct ns_desc uts_ns_desc; diff --git a/namespaces.c b/namespaces.c index 49f40234f..961d694d8 100644 --- a/namespaces.c +++ b/namespaces.c @@ -360,7 +360,7 @@ static int do_dump_namespaces(struct pid *ns_pid, unsigned int ns_flags) if (ns_flags & CLONE_NEWUTS) { pr_info("Dump UTS namespace\n"); - ret = dump_uts_ns(ns_pid->real, fdset); + ret = dump_uts_ns(ns_pid->real, ns_id); if (ret < 0) goto err; } diff --git a/uts_ns.c b/uts_ns.c index d09b546db..777b3af12 100644 --- a/uts_ns.c +++ b/uts_ns.c @@ -13,26 +13,33 @@ #include "protobuf.h" #include "protobuf/utsns.pb-c.h" -int dump_uts_ns(int ns_pid, struct cr_fdset *fdset) +int dump_uts_ns(int ns_pid, int ns_id) { - int ret; + int ret, img_fd; struct utsname ubuf; UtsnsEntry ue = UTSNS_ENTRY__INIT; + img_fd = open_image(CR_FD_UTSNS, O_DUMP, ns_id); + if (img_fd < 0) + return -1; + ret = switch_ns(ns_pid, &uts_ns_desc, NULL); if (ret < 0) - return ret; + goto err; ret = uname(&ubuf); if (ret < 0) { pr_perror("Error calling uname"); - return ret; + goto err; } ue.nodename = ubuf.nodename; ue.domainname = ubuf.domainname; - return pb_write_one(fdset_fd(fdset, CR_FD_UTSNS), &ue, PB_UTSNS); + ret = pb_write_one(img_fd, &ue, PB_UTSNS); +err: + close(img_fd); + return ret < 0 ? -1 : 0; } int prepare_utsns(int pid)