diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b8cac72..b652e6e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -40,7 +40,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] rust: - - 1.65.0 + - 1.66.0 target: - "" features: diff --git a/src/unix.rs b/src/unix.rs index c36520a..ed53bac 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -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, }; @@ -46,9 +47,14 @@ impl UnixClock { /// ``` pub fn open(path: impl AsRef) -> std::io::Result { 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;