Skip to content

add safe libc::clock_nanosleep wrapper #1315

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

Closed
wants to merge 1 commit into from
Closed

Conversation

maxbla
Copy link
Contributor

@maxbla maxbla commented Oct 13, 2020

Fixes #1299

@maxbla
Copy link
Contributor Author

maxbla commented Oct 14, 2020

libc::clock_nanosleep isn't defined for all platforms. rust-lang/libc#1922 tries to fix this.

@maxbla
Copy link
Contributor Author

maxbla commented Oct 15, 2020

this PR is waiting on the next minor release of libc

@kamalmarhubi
Copy link
Member

@maxbla

this PR is waiting on the next minor release of libc

looks like libc 0.2.80 was cut a couple of weeks ago, and includes rust-lang/libc#1922. could you bump the dependency version in Cargo.toml?

@jluebbe
Copy link

jluebbe commented Feb 15, 2021

@maxbla

looks like libc 0.2.80 was cut a couple of weeks ago, and includes rust-lang/libc#1922. could you bump the dependency version in Cargo.toml?

It seems to me that the bump is already part of the PR:
https://github.com/nix-rust/nix/pull/1315/files#diff-2e9d962a08321605940b5a657135052fbcef87b5e360662bb527c96d9a615542R20

The libc dependency has been updated in master since then, so this needs a rebase.

@maxbla
Copy link
Contributor Author

maxbla commented Feb 15, 2021

The new problem with this PR is that libc added clock_nanosleep for FreeBSD 12+ only. clock_nanosleep was implemented in FreeBSD 11.1, so libc couldn't add a wrapper for FreeBSD 11 (if it did, libc would fail to build for FreeBSD 11.0). As long as FreeBSD 11.x remains in tier 1 for nix, this PR can't be merged.

@asomers
Copy link
Member

asomers commented Feb 15, 2021

The new problem with this PR is that libc added clock_nanosleep for FreeBSD 12+ only. clock_nanosleep was implemented in FreeBSD 11.1, so libc couldn't add a wrapper for FreeBSD 11 (if it did, libc would fail to build for FreeBSD 11.0). As long as FreeBSD 11.x remains in tier 1 for nix, this PR can't be merged.

Actually, that's not a problem. For one thing, Rust's FFI bindings don't know whether a function is present at build time. And they don't care whether it's present at runtime unless somebody tries to use it. For another thing, FreeBSD 11.0 is EoL. We shouldn't worry about it anymore. Long Live FreeBSD 11.4.

@wolthom
Copy link

wolthom commented Feb 25, 2023

Are there any updates to this?

@marcfir
Copy link

marcfir commented Dec 14, 2023

Is it realistic that there will be progress here?

@SteveLauC
Copy link
Member

Gentle ping on the author @maxbla, are you still interested in finishing this PR? If not, I think I will pick it up add it to Nix:)

Copy link
Member

@SteveLauC SteveLauC left a comment

Choose a reason for hiding this comment

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

I have left some comments on what needs to be changed if you want to finish this, and a CHANGELOG entry is needed, please see CONTRIBUTING.md on how to add one.

Comment on lines +261 to +266
bitflags! {
/// Flags that are used for arming the timer.
pub struct ClockNanosleepFlags: libc::c_int {
const TIMER_ABSTIME = libc::TIMER_ABSTIME;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We should use the libc_flags macro instead:

Suggested change
bitflags! {
/// Flags that are used for arming the timer.
pub struct ClockNanosleepFlags: libc::c_int {
const TIMER_ABSTIME = libc::TIMER_ABSTIME;
}
}
libc_bitflags! {
/// Flags that are used for arming the timer.
pub struct ClockNanosleepFlags: libc::c_int {
TIMER_ABSTIME;
}
}

Copy link
Member

Choose a reason for hiding this comment

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

And, adding a doc comment for this flag would be great:)

Comment on lines +275 to +282
#[cfg(any(
target_os = "freebsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "solaris",
target_os = "illumos",
))]
Copy link
Member

Choose a reason for hiding this comment

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

We use cfg aliases now:

Suggested change
#[cfg(any(
target_os = "freebsd",
target_os = "netbsd",
target_os = "linux",
target_os = "android",
target_os = "solaris",
target_os = "illumos",
))]
#[cfg(any(
linux_android,
solarish,
target_os = "freebsd",
target_os = "netbsd"
))]

if ret == 0 {
Ok(rmtp)
} else {
Err(Error::Sys(Errno::from_i32(ret)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Err(Error::Sys(Errno::from_i32(ret)))
Err(Errno::from_i32(ret))

@SteveLauC SteveLauC mentioned this pull request Dec 30, 2023
3 tasks
@asomers asomers closed this in #2277 Jan 7, 2024
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 wrappers for some time-related syscalls
7 participants