fn send_memfd_payload(sock: UnixDatagram, data: &[u8]) -> Result<usize> {
    let memfd = {
        let tmpfd = memfd_create(
            &CString::new("libsystemd-rs-logging")?,
            MemFdCreateFlag::MFD_ALLOW_SEALING,
        )?;
        // SAFETY: `memfd_create` just returned this FD.
        let mut file = unsafe { File::from_raw_fd(tmpfd) };
        file.write_all(data)?;
        file.into_raw_fd()
    };
    // Seal the memfd, so that journald knows it can safely mmap/read it.
    fcntl(memfd, FcntlArg::F_ADD_SEALS(SealFlag::all()))?;

    let fds = &[memfd];
    let ancillary = [ControlMessage::ScmRights(fds)];
    let path = SockAddr::new_unix(SD_JOURNAL_SOCK_PATH)?;
    sendmsg(
        sock.as_raw_fd(),
        &[],
        &ancillary,
        MsgFlags::empty(),
        Some(&path),
    )?;

    Ok(data.len())
}
/// Send an overlarge payload to systemd-journald socket.
///
/// This is a slow-path for sending a large payload that could not otherwise fit
/// in a UNIX datagram. Payload is thus written to a memfd, which is sent as ancillary
/// data.
Send an overlarge payload to systemd-journald socket.
This is a slow-path for sending a large payload that could not otherwise fit
in a UNIX datagram. Payload is thus written to a memfd, which is sent as ancillary
data.
Send an overlarge payload to systemd - journald socket . This is a slow - path for sending a large payload that could not otherwise fit in a UNIX datagram . Payload is thus written to a memfd which is sent as ancillary data .
fn send_memfd_payload(sock: UnixDatagram, data: &[u8]) -> Result<usize> {
    let memfd = {
        let tmpfd = memfd_create(
            &CString::new("libsystemd-rs-logging")?,
            MemFdCreateFlag::MFD_ALLOW_SEALING,
        )?;
        // SAFETY: `memfd_create` just returned this FD.
        let mut file = unsafe { File::from_raw_fd(tmpfd) };
        file.write_all(data)?;
        file.into_raw_fd()
    };
    // Seal the memfd, so that journald knows it can safely mmap/read it.
    fcntl(memfd, FcntlArg::F_ADD_SEALS(SealFlag::all()))?;
    let fds = &[memfd];
    let ancillary = [ControlMessage::ScmRights(fds)];
    let path = SockAddr::new_unix(SD_JOURNAL_SOCK_PATH)?;
    sendmsg(
        sock.as_raw_fd(),
        &[],
        &ancillary,
        MsgFlags::empty(),
        Some(&path),
    )?;
    Ok(data.len())
}
fn send_memfd_payload ( sock : UnixDatagram , data : & [ u8 ] ) -> Result < usize > { let memfd = { let tmpfd = memfd_create ( & CString :: new ( " " ) ? , MemFdCreateFlag :: MFD_ALLOW_SEALING , ) ? ; // SAFETY: `memfd_create` just returned this FD. let mut file = unsafe { File :: from_raw_fd ( tmpfd ) } ; file . write_all ( data ) ? ; file . into_raw_fd ( ) } ; // Seal the memfd, so that journald knows it can safely mmap/read it. fcntl ( memfd , FcntlArg :: F_ADD_SEALS ( SealFlag :: all ( ) ) ) ? ; let fds = & [ memfd ] ; let ancillary = [ ControlMessage :: ScmRights ( fds ) ] ; let path = SockAddr :: new_unix ( SD_JOURNAL_SOCK_PATH ) ? ; sendmsg ( sock . as_raw_fd ( ) , & [ ] , & ancillary , MsgFlags :: empty ( ) , Some ( & path ) , ) ? ; Ok ( data . len ( ) ) }
Send an overlarge payload to systemd-journald socket.
Send an overlarge payload to systemd - journald socket .
sock
UnixDatagram
data
&[u8]