test_infra: Avoid file descriptor leak with epoll

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2022-08-09 08:41:22 -07:00 committed by Bo Chen
parent 00c1b4a95b
commit 4e31206403

View File

@ -14,7 +14,7 @@ use std::io::{Read, Write};
use std::net::TcpListener; use std::net::TcpListener;
use std::net::TcpStream; use std::net::TcpStream;
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use std::os::unix::io::AsRawFd; use std::os::unix::io::{AsRawFd, FromRawFd};
use std::path::Path; use std::path::Path;
use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::process::{Child, Command, ExitStatus, Output, Stdio};
use std::str::FromStr; use std::str::FromStr;
@ -82,6 +82,8 @@ impl GuestNetworkConfig {
// Reply on epoll w/ timeout to wait for guest connections faithfully // Reply on epoll w/ timeout to wait for guest connections faithfully
let epoll_fd = epoll::create(true).expect("Cannot create epoll fd"); let epoll_fd = epoll::create(true).expect("Cannot create epoll fd");
// Use 'File' to enforce closing on 'epoll_fd'
let _epoll_file = unsafe { fs::File::from_raw_fd(epoll_fd) };
epoll::ctl( epoll::ctl(
epoll_fd, epoll_fd,
epoll::ControlOptions::EPOLL_CTL_ADD, epoll::ControlOptions::EPOLL_CTL_ADD,