Skip to content

Module docs for std::os::unix::io inconsistent with I/O Safety discussion in std::io #124384

Closed
@jsgf

Description

@jsgf

Location

https://doc.rust-lang.org/stable/std/os/unix/io/index.html

Summary

In std::io, it correctly says:

Note that exclusive ownership of a file descriptor does not imply exclusive ownership of the underlying kernel object that the file descriptor references (also called “file description” on some operating systems). File descriptors basically work like Arc: when you receive an owned file descriptor, you cannot know whether there are any other file descriptors that reference the same kernel object. However, when you create a new kernel object, you know that you are holding the only reference to it. Just be careful not to lend it to anyone, since they can obtain a clone and then you can no longer know what the reference count is! In that sense, OwnedFd is like Arc and BorrowedFd<'a> is like &'a Arc

However the table in std::io::unix::io has the table saying:

BorrowedFd<'a> => &'a _
OwnedFd => Box<_>

This is incorrect and potentially very misleading, because the result of dupping a file descriptor creates a new fd which shares the same underlying file structure in the kernel. In particular, for seekable fds they share the current file offset (ie, used by read write and lseek) and in some cases, file locking state. (In addition to inode state and underlying file/pipe/etc contents.)

The language here should reflect the language in std::io.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions