containers / youki

A container runtime written in Rust

Home Page:https://containers.github.io/youki/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update nix to 0.28.0

YJDoc2 opened this issue · comments

ref : #2712

Nix update has some breaking changes , specifically in terms of deprecated fns , so need to update those to use non-deprecated things instead.

Hey can I take up this issue ?

Hey can I take up this issue ?

Yep, thanks! Assigned 👍

how to handle the change to the write function in nix?

// 0.27.1

/// Write to a raw file descriptor.
///
/// See also [write(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html)
pub fn write(fd: RawFd, buf: &[u8]) -> Result<usize> {
    let res = unsafe {
        libc::write(fd, buf.as_ptr() as *const c_void, buf.len() as size_t)
    };

    Errno::result(res).map(|r| r as usize)
}
// 0.28.0

/// Write to a raw file descriptor.
///
/// See also [write(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html)
pub fn write<Fd: AsFd>(fd: Fd, buf: &[u8]) -> Result<usize> {
    let res = unsafe {
        libc::write(
            fd.as_fd().as_raw_fd(),
            buf.as_ptr().cast(),
            buf.len() as size_t,
        )
    };

    Errno::result(res).map(|r| r as usize)
}

the trait bound i32: AsFd is not satisfied

the i32 can be converted to OwnedFd but the ownership is a bit confusing.

unsafe { std::os::fd::OwnedFd::from_raw_fd( fd ) }

i think a few types like ContainerType::TenantContainer { exec_notify_fd: RawFd }
must be changed to ContainerType::TenantContainer { exec_notify_fd: OwnedFd }

because in a few places like TenantContainerBuilder::build we get a OwnedFd but soon convert it to a RawFd.

        let (read_end: OwnedFd, write_end: OwnedFd) =
            pipe2(OFlag::O_CLOEXEC).map_err(LibcontainerError::OtherSyscall)?;

        let mut builder_impl = ContainerBuilderImpl {
            container_type: ContainerType::TenantContainer {
                exec_notify_fd: write_end.as_raw_fd(),
            },
            ...