From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 5/9] procfs: add variable bindings for std::fs::read
Date: Tue, 4 Mar 2025 15:40:47 +0100 [thread overview]
Message-ID: <20250304144051.585163-5-m.sandoval@proxmox.com> (raw)
In-Reply-To: <20250304144051.585163-1-m.sandoval@proxmox.com>
These will produce an error in edition 2024 otherwise. The reason this
is needed is because the `unsafe` block has its own scope.
The bytes were defined inside of the let-mut block to preserve the
lifetime they had before this commit.
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
proxmox-sys/src/linux/procfs/mod.rs | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/proxmox-sys/src/linux/procfs/mod.rs b/proxmox-sys/src/linux/procfs/mod.rs
index 3b25ce70..a1758bc0 100644
--- a/proxmox-sys/src/linux/procfs/mod.rs
+++ b/proxmox-sys/src/linux/procfs/mod.rs
@@ -228,9 +228,10 @@ static PROC_LAST_STAT: LazyLock<RwLock<(ProcFsStat, Instant, bool)>> =
pub fn read_proc_stat() -> Result<ProcFsStat, Error> {
let sample_time = Instant::now();
let update_duration;
- let mut stat =
- parse_proc_stat(unsafe { std::str::from_utf8_unchecked(&std::fs::read("/proc/stat")?) })
- .unwrap();
+ let mut stat = {
+ let bytes = std::fs::read("/proc/stat")?;
+ parse_proc_stat(unsafe { std::str::from_utf8_unchecked(&bytes) }).unwrap()
+ };
{
// read lock scope
@@ -755,7 +756,8 @@ pub struct Loadavg(pub f64, pub f64, pub f64);
impl Loadavg {
/// Read the load avage from `/proc/loadavg`.
pub fn read() -> Result<Self, Error> {
- Self::parse(unsafe { std::str::from_utf8_unchecked(&std::fs::read("/proc/loadavg")?) })
+ let bytes = std::fs::read("/proc/loadavg")?;
+ Self::parse(unsafe { std::str::from_utf8_unchecked(&bytes) })
}
/// Parse the value triplet.
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2025-03-04 14:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 14:40 [pbs-devel] [PATCH proxmox 1/9] mark extern C blocks as unsafe Maximiliano Sandoval
2025-03-04 14:40 ` [pbs-devel] [PATCH proxmox 2/9] daemon: set_var is now unsafe Maximiliano Sandoval
2025-03-04 14:40 ` [pbs-devel] [PATCH proxmox 3/9] mark blocks inside unsafe fns unsafe Maximiliano Sandoval
2025-03-04 14:40 ` [pbs-devel] [PATCH proxmox 4/9] broadcast_future: accommodate to edition 2024 changes to RPIT Maximiliano Sandoval
2025-03-04 14:40 ` Maximiliano Sandoval [this message]
2025-03-04 14:40 ` [pbs-devel] [PATCH proxmox 6/9] port to edition 2024 Maximiliano Sandoval
2025-03-04 14:40 ` [pbs-devel] [PATCH proxmox 7/9] run rustfmt with " Maximiliano Sandoval
2025-03-04 14:40 ` [pbs-devel] [PATCH proxmox 8/9] run cargo clippy --fix Maximiliano Sandoval
2025-03-04 14:40 ` [pbs-devel] [PATCH proxmox 9/9] manual clippy fixes Maximiliano Sandoval
2025-03-19 11:34 ` [pbs-devel] partially-applied: [PATCH proxmox 1/9] mark extern C blocks as unsafe Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250304144051.585163-5-m.sandoval@proxmox.com \
--to=m.sandoval@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.