init: write 1.1.1.1 to resolv.conf if /etc exists

This commit is contained in:
Alex Zenla
2024-02-08 07:26:01 +00:00
parent cfe8887c6b
commit a1aba364d6

View File

@ -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(())
}