Skip to content

Commit

Permalink
Fixed bug in opening ptp hardware clocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 committed Sep 14, 2023
1 parent 3ab6721 commit 9643f57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
rust:
- 1.65.0
- 1.66.0
target:
- ""
features:
Expand Down
10 changes: 8 additions & 2 deletions src/unix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{Clock, LeapIndicator, TimeOffset, Timestamp};
use std::{
os::unix::prelude::{AsRawFd, FromRawFd, RawFd},
os::{
fd::IntoRawFd,
unix::prelude::{FromRawFd, RawFd},
},
path::Path,
time::Duration,
};
Expand Down Expand Up @@ -46,9 +49,12 @@ impl UnixClock {
/// ```
pub fn open(path: impl AsRef<Path>) -> std::io::Result<Self> {
let file = std::fs::File::open(path)?;
Ok(Self::safe_from_raw_fd(file.as_raw_fd()))
Ok(Self::safe_from_raw_fd(file.into_raw_fd()))
}

// Cosnume an fd and produce a clock id. Clock id is only valid
// so long as the fd is open, so the RawFd here should
// not be borrowed.
fn safe_from_raw_fd(fd: RawFd) -> Self {
let clock = ((!(fd as libc::clockid_t)) << 3) | 3;

Expand Down

0 comments on commit 9643f57

Please sign in to comment.