From e79c57274bf69b0770ccade7aee5ac793d2a5ec9 Mon Sep 17 00:00:00 2001 From: "fupan.lfp" Date: Wed, 12 Aug 2020 20:33:13 +0800 Subject: [PATCH] agent: setup the "lo" interface run agent as init It should setup the "lo" interface when agent run as init porcess. Fixes: #508 Signed-off-by: fupan.lfp --- src/agent/src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 014b677833..79ed6753d9 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -28,6 +28,7 @@ extern crate slog; #[macro_use] extern crate netlink; +use crate::netlink::{RtnlHandle, NETLINK_ROUTE}; use nix::fcntl::{self, OFlag}; use nix::sys::socket::{self, AddressFamily, SockAddr, SockFlag, SockType}; use nix::sys::wait::{self, WaitStatus}; @@ -121,7 +122,8 @@ fn main() -> Result<()> { let agentConfig = AGENT_CONFIG.clone(); - if unistd::getpid() == Pid::from_raw(1) { + let init_mode = unistd::getpid() == Pid::from_raw(1); + if init_mode { // dup a new file descriptor for this temporary logger writer, // since this logger would be dropped and it's writer would // be closed out of this code block. @@ -206,11 +208,18 @@ fn main() -> Result<()> { }; // Initialize unique sandbox structure. - let s = Sandbox::new(&logger).map_err(|e| { + let mut s = Sandbox::new(&logger).map_err(|e| { error!(logger, "Failed to create sandbox with error: {:?}", e); e })?; + if init_mode { + let mut rtnl = RtnlHandle::new(NETLINK_ROUTE, 0).unwrap(); + rtnl.handle_localhost()?; + + s.rtnl = Some(rtnl); + } + let sandbox = Arc::new(Mutex::new(s)); setup_signal_handler(&logger, sandbox.clone()).unwrap();