Skip to content

Add socket_peerpidfd #1474

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ids1024
Copy link
Contributor

@ids1024 ids1024 commented Jun 11, 2025

Supported on Linux since 6.5.

I see socket_peercred is only provided on Linux, while OpenBSD (https://man.openbsd.org/getsockopt.2) has some version of SO_PEERCRED, and FreeBSD (https://man.freebsd.org/cgi/man.cgi?unix(4)) has a LOCAL_PEERCRED (libwayland for instance has code to use those on their respective platforms). These APIs do seem to be slightly different though. In any case, SO_PEERPIDFD is definitely Linux-specific for the time being.

Supported on Linux since 6.5.
@ids1024
Copy link
Contributor Author

ids1024 commented Jun 11, 2025

pidfd_getpid would also be good to add. Apparently that's not a system call, so for linux-raw we'd need to parse /proc/self/fdinfo/$pidfd for the Pid: field. But that should be fine, and not too hard.

Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, with one quick question:

@@ -277,6 +278,7 @@ fn test_select_with_sockets() {
#[test]
#[serial] // for `setrlimit` usage, and `crate::init`
fn test_select_with_maxfd_sockets() {
use rustix::fd::{FromRawFd as _, OwnedFd};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why these lines were needed in the tests, that weren't otherwise changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That fixes a compile error with cargo test --features net,process,event. Though it also works to use --features=all-apis like CI uses. (I suppose ideally it shouldn't error for any combination of features; but doesn't matter that much for tests.)

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.

2 participants