diff --git a/crates/libcgroups/src/systemd/dbus_native/dbus.rs b/crates/libcgroups/src/systemd/dbus_native/dbus.rs index 533d8d0d..9b6fa32e 100644 --- a/crates/libcgroups/src/systemd/dbus_native/dbus.rs +++ b/crates/libcgroups/src/systemd/dbus_native/dbus.rs @@ -7,7 +7,6 @@ use super::utils::{DbusError, Result, SystemdClientError}; use nix::sys::socket; use std::collections::HashMap; use std::io::{IoSlice, IoSliceMut}; -use std::mem::ManuallyDrop; use std::os::fd::AsRawFd; use std::path::PathBuf; use std::sync::atomic::{AtomicU32, Ordering}; @@ -123,7 +122,8 @@ impl DbusConnection { /// Open a new dbus connection to given address /// authenticating as user with given uid pub fn new(addr: &str, uid: u32, system: bool) -> Result { - let socket = ManuallyDrop::new(socket::socket( + // Use ManuallyDrop to keep the socket open. + let socket = std::mem::ManuallyDrop::new(socket::socket( socket::AddressFamily::Unix, socket::SockType::Stream, socket::SockFlag::empty(), diff --git a/crates/libcontainer/src/channel.rs b/crates/libcontainer/src/channel.rs index 4afab2c3..cacd84df 100644 --- a/crates/libcontainer/src/channel.rs +++ b/crates/libcontainer/src/channel.rs @@ -216,6 +216,8 @@ fn unix_channel() -> Result<(RawFd, RawFd), ChannelError> { None, socket::SockFlag::SOCK_CLOEXEC, )?; + // It is not straightforward to share the OwnedFd across forks, so we + // treat them as i32. We use ManuallyDrop to keep the connection open. let f1 = std::mem::ManuallyDrop::new(f1); let f2 = std::mem::ManuallyDrop::new(f2); diff --git a/crates/libcontainer/src/tty.rs b/crates/libcontainer/src/tty.rs index 2d306b60..495b2772 100644 --- a/crates/libcontainer/src/tty.rs +++ b/crates/libcontainer/src/tty.rs @@ -81,7 +81,7 @@ pub fn setup_console_socket( linked: linked.to_path_buf().into(), console_socket_path: console_socket_path.to_path_buf().into(), })?; - + // Using ManuallyDrop to keep the socket open. let csocketfd = std::mem::ManuallyDrop::new( socket::socket( socket::AddressFamily::Unix, @@ -117,6 +117,7 @@ pub fn setup_console(console_fd: &RawFd) -> Result<()> { let iov = [IoSlice::new(pty_name)]; let [master, slave] = [openpty_result.master, openpty_result.slave]; + // Use ManuallyDrop to keep FDs open. let master = std::mem::ManuallyDrop::new(master); let slave = std::mem::ManuallyDrop::new(slave);