Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pidfd APIs for Linux #1859

Closed
wants to merge 1 commit into from
Closed

Conversation

oxalica
Copy link

@oxalica oxalica commented Nov 10, 2022

PID file descriptors are file descriptors that refers to processes. This is a Linux specific API.
The use case is described in the manual of pidfd_open.

Added syscall wrappers:

  • pidfd_open(2)
  • pidfd_getfd(2)
  • pidfd_send_signal(2)

@JonathanWoollett-Light
Copy link
Contributor

Seems we had the same idea #1868

bors bot added a commit that referenced this pull request Dec 11, 2022
1923: feat: I/O safety for 'sys/wait' r=asomers a=SteveLauC

#### What this PR does:
1. Adds I/O safety for `sys/wait`

----------

Actually, I am not sure about which type to use here:
```rust
pub enum Id<'fd> {
    /// Wait for the child referred to by the given PID file descriptor
    #[cfg(any(target_os = "android", target_os = "linux"))]
    PIDFd(RawFd),
    PIDFd(BorrowedFd<'fd>),
}
```

If we use `Fd: AsFd`

```rust
pub enum Id<'fd, Fd: AsFd> {
    /// Wait for the child referred to by the given PID file descriptor
    #[cfg(any(target_os = "android", target_os = "linux"))]
    PIDFd(RawFd),
    PIDFd(&'fd Fd),
}
```

 then the user has to specify that generic type when using this interface, which is kinda user-unfriendly...


------

The typical usage of this interface will be something like:

```rust
// Thought currently we don't have pidfd_open(2) in `Nix`
let fd_referring_to_a_process: OwnedFd  = pidfd_open().unwrap();
let status = waitid(Id::PIDFd(fd_referring_to_a_process), WaitPidFlag::XXXX).unwrap();
```

UPDATE: `pidfd_open(2)` will be added in #1859 or #1868 .


Co-authored-by: Steve Lau <stevelauc@outlook.com>
@oxalica oxalica closed this Jan 19, 2023
@oxalica oxalica deleted the feat/pidfd branch January 19, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants