[Libct] [PATCH] ct: return an error if we can't enter into CT

Andrey Vagin avagin at openvz.org
Thu Nov 20 01:04:21 PST 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 src/ct.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/ct.c b/src/ct.c
index b6558ef..c4bab3c 100644
--- a/src/ct.c
+++ b/src/ct.c
@@ -459,7 +459,8 @@ static int local_enter_cb(ct_handler_t h, ct_process_desc_t ph, int (*cb)(void *
 {
 	struct container *ct = cth2ct(h);
 	struct process_desc *p = prh2pr(ph);
-	int aux = -1, pid;
+	int aux = -1, pid, ret;
+	int wait_pipe[2];
 
 	if (ct->state != CT_RUNNING)
 		return -LCTERR_BADCTSTATE;
@@ -469,10 +470,15 @@ static int local_enter_cb(ct_handler_t h, ct_process_desc_t ph, int (*cb)(void *
 			return -1;
 	}
 
+	if (pipe(wait_pipe))
+		return -1;
+
 	pid = fork();
 	if (pid == 0) {
 		struct ns_desc *ns;
 
+		close(wait_pipe[0]);
+
 		for (aux = 0; namespaces[aux]; aux++) {
 			ns = namespaces[aux];
 
@@ -503,13 +509,23 @@ static int local_enter_cb(ct_handler_t h, ct_process_desc_t ph, int (*cb)(void *
 		if (apply_creds(p))
 			exit(-1);
 
+		spawn_wake(wait_pipe, 0);
 		aux = cb(arg);
 		exit(aux);
 	}
 
+	close(wait_pipe[1]);
+
 	if (aux >= 0)
 		restore_ns(aux, &pid_ns);
 
+	ret = spawn_wait(wait_pipe);
+	close(wait_pipe[0]);
+	if (ret) {
+		waitpid(pid, NULL, 0);
+		return -1;
+	}
+
 	return pid;
 }
 
-- 
1.9.1



More information about the Libct mailing list