Skip to content

Commit

Permalink
Merge pull request #3 from pendulum-project/fix-phc
Browse files Browse the repository at this point in the history
Fixed bug in opening ptp hardware clocks.
  • Loading branch information
folkertdev authored Oct 2, 2023
2 parents 3ab6721 + c2b6f9c commit d36a9d1
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,7 @@
use crate::{Clock, LeapIndicator, TimeOffset, Timestamp};
use std::{
os::unix::prelude::{AsRawFd, FromRawFd, RawFd},
os::unix::io::IntoRawFd,
os::unix::prelude::{FromRawFd, RawFd},
path::Path,
time::Duration,
};
Expand Down Expand Up @@ -46,9 +47,14 @@ 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()))

// we need an owned fd. the file will be closed when the process exits.
Ok(Self::safe_from_raw_fd(file.into_raw_fd()))
}

// Consume the 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 d36a9d1

Please sign in to comment.