Skip to content

Commit

Permalink
fix time dependabot alert
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin JEROME <[email protected]>
  • Loading branch information
qjerome committed Oct 29, 2023
1 parent cd13c03 commit d56b1a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 58 deletions.
46 changes: 12 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 1 addition & 24 deletions kunai/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use chrono::prelude::*;
use core::mem::{size_of, zeroed, MaybeUninit};
use core::mem::{size_of, MaybeUninit};
use ip_network::IpNetwork;
use md5::{Digest, Md5};
use sha1::Sha1;
Expand All @@ -23,28 +22,6 @@ pub fn get_clk_tck() -> i64 {
unsafe { libc::sysconf(libc::_SC_CLK_TCK) }
}

// inspired from: https://github.com/itchyny/uptime-rs
// the code panics if we cannot retrieve boot time
#[allow(dead_code)]
pub fn get_boot_time() -> DateTime<Utc> {
let mut info: libc::sysinfo = unsafe { zeroed() };
let ret = unsafe { libc::sysinfo(&mut info) };
if ret != 0 {
panic!("failed to retrieve sysinfo");
}

// we have to work with seconds as sysinfo returns time since boot in seconds
#[allow(clippy::unnecessary_cast)]
let boot_time_sec = Utc::now()
.timestamp()
.checked_sub(info.uptime as i64)
.unwrap();
DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp_opt(boot_time_sec, 0).unwrap(),
Utc,
)
}

#[derive(Debug)]
pub enum RandError {
CallFailure,
Expand Down

0 comments on commit d56b1a8

Please sign in to comment.