-
Notifications
You must be signed in to change notification settings - Fork 13k
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
socket ancillary data implementation for FreeBSD (from 13 and above). #91793
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
bb58a89
to
8e614f9
Compare
☔ The latest upstream changes (presumably #92062) made this pull request unmergeable. Please resolve the merge conflicts. |
8e614f9
to
f63811d
Compare
ping :) |
This comment has been minimized.
This comment has been minimized.
24f96d0
to
296c1f9
Compare
☔ The latest upstream changes (presumably #95702) made this pull request unmergeable. Please resolve the merge conflicts. |
cc @Amanieu :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall but I'd like someone more familiar with FreeBSD to have a second look.
cc @asomers
library/std/src/os/freebsd/fs.rs
Outdated
panic!("as_raw_stat not supported with FreeBSD 12 ABI"); | ||
#[cfg(not(freebsd12))] | ||
#[cfg(not(any(freebsd12, freebsd13)))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If build.rs defines both freebsd12
and freebsd13
then this shouldn't be needed.
library/std/src/sys/unix/net.rs
Outdated
@@ -430,6 +430,17 @@ impl Socket { | |||
Ok(passcred != 0) | |||
} | |||
|
|||
#[cfg(all(target_os = "freebsd", freebsd13))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(freebsd13)]
should be enough here.
target_os = "android", | ||
target_os = "linux", | ||
target_os = "dragonfly", | ||
all(target_os = "freebsd", freebsd13) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly ok overall. However, gating this feature on freebsd13 means that it won't be available on builds from rustup, probably not for years. However, all relevant symbols are defined in libc, which means the code could be successfully built when using the freebsd12 (or 11, or 10) ABI. Then, if you try to use it on freebsd12, you'll just get an ENOPROTOOPT
error. IMHO, that's not so bad. So why not enable it on all freebsd builds? That way it will be available to rustup users.
Also, you should adjust the target_os
gate on some of the functions in library/std/src/os/unix/net/tests.rs .
|
||
#[cfg(all(target_os = "freebsd", freebsd13))] | ||
pub fn passcred(&self) -> io::Result<bool> { | ||
let passcred: libc::c_int = getsockopt(self, libc::AF_LOCAL, libc::LOCAL_CREDS_PERSISTENT)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use LOCAL_CREDS_PERSISTENT for FreeBSD, but LOCAL_CREDS for NetBSD?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because LOCAL_CREDS_PERSISTENT is used in conjunction with sockcred2
as opposed to LOCAL_CREDS and sockcred
which does not get the process id on FreeBSD. NetBSD does not have the same history regarding this feature.
any( | ||
target_os = "android", | ||
target_os = "linux", | ||
target_os = "dragonfly", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_os = "dragonfly", | |
target_os = "netbsd", |
not(any( | ||
target_os = "android", | ||
target_os = "linux", | ||
target_os = "dragonfly", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_os = "dragonfly", | |
target_os = "netbsd", |
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")] | ||
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")] | ||
#[cfg_attr( | ||
any(target_os = "android", target_os = "linux", all(target_os = "freebsd", freebsd13),), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any(target_os = "android", target_os = "linux", all(target_os = "freebsd", freebsd13),), | |
any(target_os = "android", target_os = "linux", target_os = "netbsd", all(target_os = "freebsd", freebsd13),), |
not(any( | ||
target_os = "android", | ||
target_os = "linux", | ||
all(target_os = "freebsd", freebsd13) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all(target_os = "freebsd", freebsd13) | |
target_os = "netbsd", | |
all(target_os = "freebsd", freebsd13) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all(target_os = "freebsd", freebsd13) | |
target_os = "freebsd" |
And do the same on lines 884 and 896 as well.
@@ -270,6 +360,7 @@ impl SocketCred { | |||
} | |||
|
|||
/// Get the current PID. | |||
#[must_use] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, why put #[must_use]
here, but not on get_pid
or get_uid
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is in the netbsd implementation. Also it's missing from the other get_*
in the netbsd implementation.
@@ -326,11 +417,15 @@ pub struct ScmCredentials<'a>(AncillaryDataIter<'a, ()>); | |||
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] | |||
pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::ucred>); | |||
|
|||
#[cfg(freebsd13)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to change the #[cfg(
statement on line 409 or else this will be defined twice.
@@ -605,7 +702,7 @@ impl<'a> SocketAncillary<'a> { | |||
/// The function returns `true` if there was enough space in the buffer. | |||
/// If there was not enough space then no credentials was appended. | |||
/// Technically, that means this operation adds a control message with the level `SOL_SOCKET` | |||
/// and type `SCM_CREDENTIALS` or `SCM_CREDS`. | |||
/// and type `SCM_CREDENTIALS` or `SCM_CREDS` or `SCM_CREDS2`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// and type `SCM_CREDENTIALS` or `SCM_CREDS` or `SCM_CREDS2`. | |
/// and type `SCM_CREDENTIALS`, `SCM_CREDS`, or `SCM_CREDS2`. |
/// The function returns `true` if there was enough space in the buffer. | ||
/// If there was not enough space then no credentials was appended. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// The function returns `true` if there was enough space in the buffer. | |
/// If there was not enough space then no credentials was appended. | |
/// The function returns `true` if there is enough space in the buffer. | |
/// If there is not enough space then no credentials will be appended. |
@@ -623,6 +720,19 @@ impl<'a> SocketAncillary<'a> { | |||
) | |||
} | |||
|
|||
#[cfg(freebsd13)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's inconsistent to redefine the function for FreeBSD, but share a definition for Linux and NetBSD. There's only one line of difference, so why not share a single definition for all OSes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point I forgot but I started this change before the netbsd changes was ever committed most likely this reason is gone :)
This comment has been minimized.
This comment has been minimized.
target_os = "android", | ||
target_os = "linux", | ||
target_os = "netbsd", | ||
all(target_os = "freebsd", freebsd13), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all(target_os = "freebsd", freebsd13), | |
target_os = "freebsd", |
not(any( | ||
target_os = "android", | ||
target_os = "linux", | ||
all(target_os = "freebsd", freebsd13) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all(target_os = "freebsd", freebsd13) | |
target_os = "freebsd" |
And do the same on lines 884 and 896 as well.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
e2046e1
to
91a6898
Compare
ping :) |
Ping: |
I think this is ready to be merged if freebsd folks are still happy with it? |
Nothing's changed on the OS side. I still approve, assuming none of the force-pushes broke something (I didn't closely review the force-pushes after 8-May-2022) |
Ok I'm happy to merge this, CI permitting. The only thing I'd ask, @devnexen, is that you squish the two commits into one. |
introducing new build config as well.
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Edit: bors not responding |
@bors r+ |
Rollup of 8 pull requests Successful merges: - rust-lang#91793 (socket ancillary data implementation for FreeBSD (from 13 and above).) - rust-lang#92284 (Change advance(_back)_by to return the remainder instead of the number of processed elements) - rust-lang#102472 (stop special-casing `'static` in evaluation) - rust-lang#108480 (Use Rayon's TLV directly) - rust-lang#109321 (Erase impl regions when checking for impossible to eagerly monomorphize items) - rust-lang#109470 (Correctly substitute GAT's type used in `normalize_param_env` in `check_type_bounds`) - rust-lang#109562 (Update ar_archive_writer to 0.1.3) - rust-lang#109629 (remove obsolete `givens` from regionck) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fix documentation build on FreeBSD After the socket ancillary data implementation was introduced, the documentation build was broken on FreeBSD hosts, add the same workaround as for the existing implementations. Fixes the doc build after rust-lang#91793
Fix documentation build on FreeBSD After the socket ancillary data implementation was introduced, the documentation build was broken on FreeBSD hosts, add the same workaround as for the existing implementations. Fixes the doc build after rust-lang#91793
introducing new build config as well.