From a1aba364d621e9f72095f705fdaabd37751c7a2f Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Thu, 8 Feb 2024 07:26:01 +0000 Subject: [PATCH] init: write 1.1.1.1 to resolv.conf if /etc exists --- container/src/init.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/container/src/init.rs b/container/src/init.rs index c0712e9..c2677fe 100644 --- a/container/src/init.rs +++ b/container/src/init.rs @@ -13,8 +13,9 @@ use std::net::Ipv4Addr; use std::os::fd::AsRawFd; use std::os::linux::fs::MetadataExt; use std::os::unix::fs::{chroot, PermissionsExt}; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::ptr::addr_of_mut; +use std::str::FromStr; use std::thread::sleep; use std::time::Duration; use sys_mount::{FilesystemType, Mount, MountFlags}; @@ -324,6 +325,14 @@ impl ContainerInit { } else { warn!("unable to find link named {}", network.link); } + + let etc = PathBuf::from_str("/etc")?; + if !etc.exists() { + fs::create_dir(etc)?; + } + let resolv = PathBuf::from_str("/etc/resolv.conf")?; + fs::write(resolv, "nameserver 1.1.1.1\n")?; + Ok(()) }