From 32ebe1895bc2daffacf1e0654d33ce418c7ec068 Mon Sep 17 00:00:00 2001 From: Fupan Li Date: Thu, 16 Feb 2023 11:23:11 +0800 Subject: [PATCH] agent: fix the issue of creating the dns file We should make sure the dns's source file's parent directory exist, otherwise, it would failed to create the file directly. Signed-off-by: Fupan Li --- src/agent/src/network.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/agent/src/network.rs b/src/agent/src/network.rs index 451b5064d0..2e617dc3bf 100644 --- a/src/agent/src/network.rs +++ b/src/agent/src/network.rs @@ -7,6 +7,7 @@ use anyhow::{anyhow, Result}; use nix::mount::{self, MsFlags}; use slog::Logger; use std::fs; +use std::path; const KATA_GUEST_SANDBOX_DNS_FILE: &str = "/run/kata-containers/sandbox/resolv.conf"; const GUEST_DNS_FILE: &str = "/etc/resolv.conf"; @@ -64,6 +65,12 @@ fn do_setup_guest_dns(logger: Logger, dns_list: Vec, src: &str, dst: &st .map(|x| x.trim()) .collect::>() .join("\n"); + + // make sure the src file's parent path exist. + let file_path = path::Path::new(src); + if let Some(p) = file_path.parent() { + fs::create_dir_all(p)?; + } fs::write(src, content)?; // bind mount to /etc/resolv.conf