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

Added FreeBSD's SCM_REALTIME and SCM_MONOTONIC into sys::socket::ControlMessageOwned #2187

Merged
merged 15 commits into from
Nov 25, 2023

Conversation

recatek
Copy link
Contributor

@recatek recatek commented Nov 13, 2023

What does this PR do

Adds FreeBSD's SCM_REALTIME and SCM_MONOTONIC into sys::socket::ControlMessageOwned to read socket control messages after setting SO_TS_CLOCK to either SO_TS_REALTIME or SO_TS_MONOTONIC. Note that this does not also support SO_TS_BINTIME yet as that requires a new data structure. See man setsockopt for FreeBSD for more info on these settings.

Also adds a proper enum as a parameter to sockopt::TsClock for choosing which clock to timestamp with. Previously this took a raw i32 and required libc as a dependency to properly configure.

Resolves #2186.

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

src/sys/socket/mod.rs Outdated Show resolved Hide resolved
@recatek
Copy link
Contributor Author

recatek commented Nov 14, 2023

Regarding the changelog entry, I noticed there isn't a section for upcoming changes. Should I create one?

@SteveLauC
Copy link
Member

Regarding the changelog entry, I noticed there isn't a section for upcoming changes. Should I create one?

Yep, a changelog entry is needed, but we don't edit that CHANGELOG.md file, instead, we add a new file to the changelog directory, please see CONTRIBUTING.md on how to add a change log

@asomers
Copy link
Member

asomers commented Nov 18, 2023

This looks good @recatek . Would it be possible to add a test too?

@recatek
Copy link
Contributor Author

recatek commented Nov 18, 2023

Added tests for the new enum and the two new control messages.

test/sys/test_socket.rs Outdated Show resolved Hide resolved
test/sys/test_socket.rs Outdated Show resolved Hide resolved
test/sys/test_socket.rs Outdated Show resolved Hide resolved
test/sys/test_socket.rs Outdated Show resolved Hide resolved
test/sys/test_socket.rs Outdated Show resolved Hide resolved
@recatek recatek requested a review from asomers November 21, 2023 03:55
@recatek
Copy link
Contributor Author

recatek commented Nov 21, 2023

Not sure what happened there in that CI / tier3 (armv7-unknown-linux-uclibceabihf) test -- any ideas?

@SteveLauC
Copy link
Member

Well, that CI error does not seem to be related to this PR

I can reproduce it on my Linux host:

$ cargo +nightly -v
cargo 1.76.0-nightly (71cd3a926 2023-11-20)

$ cargo new hello

$ cd hello

$ cargo +nightly b -Zbuild-std --target armv7-unknown-linux-uclibceabihf
   Compiling compiler_builtins v0.1.103
   Compiling core v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.150
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
   Compiling rustc-std-workspace-core v1.99.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling adler v1.0.2
   Compiling rustc-demangle v0.1.23
   Compiling unwind v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-alloc v1.99.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
   Compiling panic_abort v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort)
   Compiling panic_unwind v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_unwind)
   Compiling gimli v0.28.0
   Compiling hashbrown v0.14.2
   Compiling object v0.32.1
   Compiling std_detect v0.1.5 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling miniz_oxide v0.7.1
   Compiling addr2line v0.21.0
error[E0599]: no method named `si_pid` found for struct `siginfo_t` in the current scope
   --> /home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/process/process_unix.rs:879:33
    |
879 |             if unsafe { siginfo.si_pid() } == 0 {
    |                                 ^^^^^^ method not found in `siginfo_t`

error[E0599]: no method named `si_status` found for struct `siginfo_t` in the current scope
   --> /home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/process/process_unix.rs:917:39
    |
917 |         let status = unsafe { siginfo.si_status() };
    |                                       ^^^^^^^^^ method not found in `siginfo_t`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `std` (lib) due to 2 previous errors

Though I can not reproduce it if I choose the target to be x86_64-unknown-linux-gnu:

$ cargo +nightly b -Zbuild-std --target x86_64-unknown-linux-gnu
   Compiling compiler_builtins v0.1.103
   Compiling core v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.150
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
   Compiling rustc-std-workspace-core v1.99.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling adler v1.0.2
   Compiling rustc-demangle v0.1.23
   Compiling unwind v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-alloc v1.99.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
   Compiling panic_abort v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort)
   Compiling panic_unwind v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_unwind)
   Compiling gimli v0.28.0
   Compiling std_detect v0.1.5 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling miniz_oxide v0.7.1
   Compiling object v0.32.1
   Compiling hashbrown v0.14.2
   Compiling addr2line v0.21.0
   Compiling proc_macro v0.0.0 (/home/steve/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro)
   Compiling hello v0.1.0 (/tmp/hello)
    Finished dev [unoptimized + debuginfo] target(s) in 8.37s

@SteveLauC SteveLauC mentioned this pull request Nov 21, 2023
3 tasks
@SteveLauC SteveLauC mentioned this pull request Nov 23, 2023
@SteveLauC SteveLauC added this pull request to the merge queue Nov 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 24, 2023
@SteveLauC
Copy link
Member

Hi @recatek, you need to handle that CI failure, wrap unsafe functions in unsafe blocks. Though it does confuse me why the check for this PR actually passed then it failed in the merge queue

@recatek
Copy link
Contributor Author

recatek commented Nov 24, 2023

Looks like we're good now. Got caught up in upstream changes.

@SteveLauC SteveLauC added this pull request to the merge queue Nov 25, 2023
Merged via the queue into nix-rust:master with commit 3541bdd Nov 25, 2023
34 checks passed
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.

Add support for SCM_MONOTONIC as a control message for FreeBSD.
3 participants