Skip to main content

write_without_waiting_for_a_reader

Function write_without_waiting_for_a_reader 

Source
pub fn write_without_waiting_for_a_reader(
    fd: i32,
    bytes: &[u8],
) -> Result<usize, Error>
Expand description

One write of bytes to fd that cannot wait for a reader to drain the file, for a writer that then waits itself, within its own bound, when it is told the file is full (crate::util::RetryingStderr while diagnostics_must_not_wait). Returns the bytes written, which may be fewer than bytes.len(), or the error; WouldBlock means full.

THE DESCRIPTOR ITSELF IS NEVER MADE NON-BLOCKING, as in write_without_waiting:

  • a pipe, a FIFO or any character device, a terminal or /dev/null: one write through a new O_NONBLOCK open file description for the same object (see write_without_waiting). Opening a pipe that has no reader fails with ENXIO, reported here as EPIPE, what a write to it would have returned. If the new description cannot be opened, nothing is written and the error is returned.

    ⚠️ NO CHARACTER DEVICE GETS A PLAIN WRITE, not even one the terminal query says is not a terminal. Nothing the process asks can tell a terminal from /dev/null in a way a seccomp policy cannot forge: a policy that answers the query with ENOTTY makes a terminal look like /dev/null, and a plain write to a full terminal waits for a reader forever.

  • a socket: send(MSG_DONTWAIT | MSG_NOSIGNAL).

  • anything else, a regular file included: a plain write(2). Nothing reads a regular file, so the write cannot wait for a reader to drain it; and RWF_NOWAIT would refuse buffered writes on btrfs and tmpfs, which would lose every line of a log written there. A regular file on a network or FUSE file system whose server has stopped answering can still hold this write.

  • a descriptor whose type cannot be learned (see file_type in this module): nothing is written, and the error is returned, so the caller gives up on the bytes.

No SIGPIPE, SIGXFSZ or SIGTTOU escapes; see suppressing_diagnostic_signals.