diff options
author | Kamil Ogórek <kamil.ogorek@gmail.com> | 2022-12-28 14:56:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-28 14:56:05 +0100 |
commit | 65ea554afe1ce387ea1d663e6178079ebcf0904f (patch) | |
tree | 36d6f38dad457cc24979634d8789f85868a0e30d /runtime/ops/os/sys_info.rs | |
parent | 8bdf66c59c7424759f441e19047d7ffc0bf13ef3 (diff) |
fix(node): Add op_node_unstable_os_uptime to allow for node interop (#17208)
Diffstat (limited to 'runtime/ops/os/sys_info.rs')
-rw-r--r-- | runtime/ops/os/sys_info.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/runtime/ops/os/sys_info.rs b/runtime/ops/os/sys_info.rs index ecb40b9a0..91422546c 100644 --- a/runtime/ops/os/sys_info.rs +++ b/runtime/ops/os/sys_info.rs @@ -302,6 +302,8 @@ pub fn mem_info() -> Option<MemInfo> { } pub fn os_uptime() -> u64 { + let mut uptime: u64 = 0; + #[cfg(target_os = "linux")] { let mut info = std::mem::MaybeUninit::uninit(); @@ -310,7 +312,7 @@ pub fn os_uptime() -> u64 { if res == 0 { // SAFETY: `sysinfo` initializes the struct. let info = unsafe { info.assume_init() }; - return info.uptime as u64; + uptime = info.uptime as u64; } } @@ -340,7 +342,7 @@ pub fn os_uptime() -> u64 { ) }; if res == 0 { - return SystemTime::now() + uptime = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .map(|d| { (d - Duration::new( @@ -357,8 +359,8 @@ pub fn os_uptime() -> u64 { unsafe { // Windows is the only one that returns `uptime` in milisecond precision, // so we need to get the seconds out of it to be in sync with other envs. - return unsafe { winapi::um::sysinfoapi::GetTickCount64() as u64 / 1000 }; + uptime = winapi::um::sysinfoapi::GetTickCount64() as u64 / 1000; } - 0 + uptime } |