[CRIU] [PATCH 6/9] unix: Move shared data init into early stage

Cyrill Gorcunov gorcunov at gmail.com
Tue Aug 28 16:21:21 MSK 2018


We will need to take mutex when bind()
bindmounted sockets. Strictly speaking we
won't support bindmounted and deleted sockets
for now but better prepare this scaffolds early.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/cr-restore.c      |  3 +++
 criu/include/sockets.h |  1 +
 criu/sk-unix.c         | 10 +++++++---
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 204708794841..b25fc270455d 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -257,6 +257,9 @@ static int crtools_prepare_shared(void)
 	if (prepare_cgroup())
 		return -1;
 
+	if (unix_prepare_shared())
+		return -1;
+
 	return 0;
 }
 
diff --git a/criu/include/sockets.h b/criu/include/sockets.h
index d56e25d07c12..3577ac6d0d14 100644
--- a/criu/include/sockets.h
+++ b/criu/include/sockets.h
@@ -60,6 +60,7 @@ extern int netlink_receive_one(struct nlmsghdr *hdr, struct ns_id *ns, void *arg
 extern int unix_sk_id_add(unsigned int ino);
 extern int unix_sk_ids_parse(char *optarg);
 extern int unix_prepare_root_shared(void);
+extern int unix_prepare_shared(void);
 
 extern int do_dump_opt(int sk, int level, int name, void *val, int len);
 #define dump_opt(s, l, n, f)	do_dump_opt(s, l, n, f, sizeof(*f))
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 70009b02fec3..6b47b8cd2f67 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -2131,16 +2131,20 @@ static int init_unix_sk_info(struct unix_sk_info *ui, UnixSkEntry *ue)
 	return 0;
 }
 
-int unix_prepare_root_shared(void)
+int unix_prepare_shared(void)
 {
-	struct unix_sk_info *ui;
-
 	mutex_ghost = shmalloc(sizeof(*mutex_ghost));
 	if (!mutex_ghost) {
 		pr_err("ghost: Can't allocate mutex\n");
 		return -ENOMEM;
 	}
 	mutex_init(mutex_ghost);
+	return 0;
+}
+
+int unix_prepare_root_shared(void)
+{
+	struct unix_sk_info *ui;
 
 	pr_debug("ghost: Resolving addresses\n");
 
-- 
2.17.1



More information about the CRIU mailing list