mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-11-04 11:50:15 +00:00 
			
		
		
		
	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 <fupan.lfp@antfin.com>
This commit is contained in:
		@@ -28,6 +28,7 @@ extern crate slog;
 | 
				
			|||||||
#[macro_use]
 | 
					#[macro_use]
 | 
				
			||||||
extern crate netlink;
 | 
					extern crate netlink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::netlink::{RtnlHandle, NETLINK_ROUTE};
 | 
				
			||||||
use nix::fcntl::{self, OFlag};
 | 
					use nix::fcntl::{self, OFlag};
 | 
				
			||||||
use nix::sys::socket::{self, AddressFamily, SockAddr, SockFlag, SockType};
 | 
					use nix::sys::socket::{self, AddressFamily, SockAddr, SockFlag, SockType};
 | 
				
			||||||
use nix::sys::wait::{self, WaitStatus};
 | 
					use nix::sys::wait::{self, WaitStatus};
 | 
				
			||||||
@@ -121,7 +122,8 @@ fn main() -> Result<()> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    let agentConfig = AGENT_CONFIG.clone();
 | 
					    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,
 | 
					        // dup a new file descriptor for this temporary logger writer,
 | 
				
			||||||
        // since this logger would be dropped and it's writer would
 | 
					        // since this logger would be dropped and it's writer would
 | 
				
			||||||
        // be closed out of this code block.
 | 
					        // be closed out of this code block.
 | 
				
			||||||
@@ -206,11 +208,18 @@ fn main() -> Result<()> {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Initialize unique sandbox structure.
 | 
					    // 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);
 | 
					        error!(logger, "Failed to create sandbox with error: {:?}", e);
 | 
				
			||||||
        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));
 | 
					    let sandbox = Arc::new(Mutex::new(s));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setup_signal_handler(&logger, sandbox.clone()).unwrap();
 | 
					    setup_signal_handler(&logger, sandbox.clone()).unwrap();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user