1
0
mirror of https://github.com/kata-containers/kata-containers.git synced 2025-04-29 12:14:48 +00:00

agent: fix the issue of creating new namespaces for agent

The tokio's spawn will only create an future async task
instead of a new real thread, thus executing unshare to
create a new namespace in tokio's async task would make
the agent process to join in the new created namespace,
which isn't expected.

Thus, we'd better to to the unshare in a real thread to
prevent moving the agent process into a new namespace.

Fixes: 

Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
This commit is contained in:
Fupan Li 2021-12-30 11:25:41 +08:00
parent 820dc930db
commit ea1a173854

View File

@ -100,7 +100,7 @@ impl Namespace {
self.path = new_ns_path.clone().into_os_string().into_string().unwrap();
let hostname = self.hostname.clone();
let new_thread = tokio::spawn(async move {
let new_thread = std::thread::spawn(move || {
if let Err(err) = || -> Result<()> {
let origin_ns_path = get_current_thread_ns_path(ns_type.get());
@ -148,7 +148,7 @@ impl Namespace {
});
new_thread
.await
.join()
.map_err(|e| anyhow!("Failed to join thread {:?}!", e))??;
Ok(self)