From 95fdc37e52a3ddad294ede18e39f5cc065791abf Mon Sep 17 00:00:00 2001 From: vasilito Date: Mon, 6 Jul 2026 23:42:25 +0300 Subject: [PATCH] redbear-power: add set_nice() syscall helper for nice/renice editor --- .../redbear-power/source/src/process.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/local/recipes/system/redbear-power/source/src/process.rs b/local/recipes/system/redbear-power/source/src/process.rs index aeff664920..c0ff82f59b 100644 --- a/local/recipes/system/redbear-power/source/src/process.rs +++ b/local/recipes/system/redbear-power/source/src/process.rs @@ -1987,3 +1987,23 @@ mod io_sort_unit_tests { assert_eq!(read_cpu_affinity(999_999_999), None); } } + + +/// Set the nice value of a process via setpriority(2). htop F7/F8 feature. +pub fn set_nice(pid: u32, nice: i32) -> Result<(), String> { + let n = nice.clamp(-20, 19); + #[cfg(target_os = "linux")] + unsafe { + // PRIO_PROCESS = 0, who = pid + if libc::setpriority(0, pid as u32, n) == 0 { + Ok(()) + } else { + Err(std::io::Error::last_os_error().to_string()) + } + } + #[cfg(not(target_os = "linux"))] + { + let _ = (pid, n); + Err("setpriority not supported on this platform".into()) + } +}