Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.26 fix cpu #7

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.26.9

* Linux: Improve compatibility with upcoming `libc` changes for musl targets.

# 0.26.8

* Add `ProcessExt::session_id` method.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sysinfo"
version = "0.26.8"
version = "0.26.9"
authors = ["Guillaume Gomez <[email protected]>"]

description = "Library to get system information such as processes, CPUs, disks, components and networks"
Expand Down
46 changes: 33 additions & 13 deletions src/linux/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,39 @@ impl CpusWrapper {
brand.clone(),
));
} else {
parts.next(); // we don't want the name again
self.cpus[i].set(
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
);
// Prevents "index out of bounds" error caused by non-stop cpu expansion.
if i < self.cpus.len() {
parts.next(); // we don't want the name again
self.cpus[i].set(
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
);
} else {
self.cpus.push(Cpu::new_with_values(
to_str!(parts.next().unwrap_or(&[])),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
parts.next().map(to_u64).unwrap_or(0),
0,
vendor_id.clone(),
brand.clone(),
));
}
}

i += 1;
Expand Down
5 changes: 1 addition & 4 deletions src/linux/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ fn boot_time() -> u64 {
}
}
// Either we didn't find "btime" or "/proc/stat" wasn't available for some reason...
let mut up = libc::timespec {
tv_sec: 0,
tv_nsec: 0,
};
unsafe {
let mut up: libc::timespec = std::mem::zeroed();
if libc::clock_gettime(libc::CLOCK_BOOTTIME, &mut up) == 0 {
up.tv_sec as u64
} else {
Expand Down