From 07bdd62f29551d2f8fb994917050cb734b2e88b9 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Tue, 10 Jan 2023 11:57:51 -0500 Subject: [PATCH 1/4] Update use of `libc::timespec` to prepare for future libc version In a future release of the `libc` crate, `libc::timespec` will contain private padding fields on `*-linux-musl` targets and so the struct will no longer be able to be created using the literal initialization syntax. Update the use of `libc::timespec` to create a value by calling `std::mem::zeroed()` which works with both current versions of `libc` as well as the future version which contains that change. --- src/linux/system.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/linux/system.rs b/src/linux/system.rs index 3c4fce345..c643070b5 100644 --- a/src/linux/system.rs +++ b/src/linux/system.rs @@ -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 { From b75356bef55b091e84e85a407409b167226e9268 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 Jan 2023 20:52:03 +0100 Subject: [PATCH 2/4] Update CHANGELOG for 0.26.9 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a0117c8..c33938be7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. From 9e6661d570e8b8b0d3e62ca1cc84a2371b9f1624 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 Jan 2023 20:52:20 +0100 Subject: [PATCH 3/4] Update crate version to 0.26.9 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 40dbe234e..b0365aabc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sysinfo" -version = "0.26.8" +version = "0.26.9" authors = ["Guillaume Gomez "] description = "Library to get system information such as processes, CPUs, disks, components and networks" From 5a1bcf08816979624ef2ad79cfb896de432a9501 Mon Sep 17 00:00:00 2001 From: mornyx Date: Tue, 27 Jun 2023 00:47:55 +0800 Subject: [PATCH 4/4] fix index out of bounds error Signed-off-by: mornyx --- src/linux/cpu.rs | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/linux/cpu.rs b/src/linux/cpu.rs index 103f5362a..a200b1ff1 100644 --- a/src/linux/cpu.rs +++ b/src/linux/cpu.rs @@ -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;