aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-08-19 19:48:09 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-09-01 17:00:27 +0200
commitd5b3467056856f6f85b81d0b5f4fb4c67da74642 (patch)
treebd067ba30b84d9788504839a6d6bfd47dc90298e
parent088d19fbb81be997be7ade437e7e9c079b0387b8 (diff)
downloadpasst-d5b3467056856f6f85b81d0b5f4fb4c67da74642.tar
passt-d5b3467056856f6f85b81d0b5f4fb4c67da74642.tar.gz
passt-d5b3467056856f6f85b81d0b5f4fb4c67da74642.tar.bz2
passt-d5b3467056856f6f85b81d0b5f4fb4c67da74642.tar.lz
passt-d5b3467056856f6f85b81d0b5f4fb4c67da74642.tar.xz
passt-d5b3467056856f6f85b81d0b5f4fb4c67da74642.tar.zst
passt-d5b3467056856f6f85b81d0b5f4fb4c67da74642.zip
pasta: If a new namespace is created, wait for it to be ready before proceeding
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--passt.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/passt.c b/passt.c
index 0f8ac77..73c537a 100644
--- a/passt.c
+++ b/passt.c
@@ -154,6 +154,18 @@ static void pasta_child_handler(int signal)
}
/**
+ * pasta_wait_for_ns() - Busy loop until we can enter the target namespace
+ * @target_pid: PID of process associated with target namespace
+ *
+ * Return: 0
+ */
+static int pasta_wait_for_ns(void *target_pid)
+{
+ while (ns_enter(*(int *)target_pid));
+ return 0;
+}
+
+/**
* pasta_start_ns() - Fork shell in new namespace if target PID is not given
* @c: Execution context
*/
@@ -178,8 +190,10 @@ static void pasta_start_ns(struct ctx *c)
exit(EXIT_FAILURE);
}
- if ((pasta_child_pid = c->pasta_pid))
+ if ((pasta_child_pid = c->pasta_pid)) {
+ NS_CALL(pasta_wait_for_ns, &pasta_child_pid);
return;
+ }
if (unshare(CLONE_NEWNET | CLONE_NEWUSER)) {
perror("unshare");