1
0
mirror of https://github.com/containers/youki synced 2024-11-23 01:11:58 +01:00

add comments

Signed-off-by: anti-entropy123 <1348651580@qq.com>
This commit is contained in:
anti-entropy123 2023-10-09 10:17:12 +08:00
parent 59937cf490
commit 705b17a54b
3 changed files with 6 additions and 3 deletions

@ -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<Self> {
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(),

@ -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);

@ -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);