Skip to content

Commit 4d1fab2

Browse files
committed
fix: create NamespaceConfig resource after writing resolv.conf file
Moved NamespaceConfig::create() to after the resolv.conf file is written to ensure the file exists before the resource tracks it for cleanup.
1 parent 0a89b9f commit 4d1fab2

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/jail/linux/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,6 @@ impl LinuxJail {
431431
.with_context(|| format!("Failed to create directory: {}", netns_namespace_dir))?;
432432
debug!("Created directory: {}", netns_namespace_dir);
433433

434-
// Create namespace config resource
435-
self.namespace_config = Some(ManagedResource::<NamespaceConfig>::create(
436-
&self.config.jail_id,
437-
)?);
438-
439434
// Write custom resolv.conf that will be bind-mounted into the namespace
440435
// Point directly to the host's veth IP where our DNS server listens
441436
let resolv_conf_path = format!("{}/resolv.conf", netns_namespace_dir);
@@ -459,6 +454,12 @@ nameserver {}\n",
459454
anyhow::bail!("Failed to create resolv.conf at {}", resolv_conf_path);
460455
}
461456

457+
// Create namespace config resource for cleanup tracking
458+
// IMPORTANT: Create this AFTER writing resolv.conf to ensure the file exists
459+
self.namespace_config = Some(ManagedResource::<NamespaceConfig>::create(
460+
&self.config.jail_id,
461+
)?);
462+
462463
Ok(())
463464
}
464465

0 commit comments

Comments
 (0)