Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ prettytable-rs = "0.10.0"
rand = { version = "0.10.0" }
ratatui = "0.30.0"
regex = "1.10.4"
rustix = { version = "1.1.2", features = ["fs", "process"] }
rustix = { version = "1.1.2", features = ["fs", "process", "param"] }
sysinfo = "0.38.0"
tempfile = "3.10.1"
terminal_size = "0.4.2"
Expand Down
1 change: 1 addition & 0 deletions src/uu/top/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ratatui = { workspace = true, features = ["crossterm"] }
sysinfo = { workspace = true }
chrono = { workspace = true }
bytesize = { workspace = true }
rustix = { workspace = true }

uu_vmstat = { path = "../vmstat" }
uu_w = { path = "../w" }
Expand Down
10 changes: 3 additions & 7 deletions src/uu/top/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

#[cfg(target_os = "linux")]
pub(crate) fn renice(pid: u32, nice_value: i32) -> uucore::error::UResult<()> {
use rustix::process::{setpriority_process, Pid};
use uucore::error::USimpleError;
use uucore::libc::{setpriority, PRIO_PROCESS};

let result = unsafe { setpriority(PRIO_PROCESS, pid, nice_value) };
if result == -1 {
Err(USimpleError::new(0, "Permission Denied"))
} else {
Ok(())
}
let pid = Pid::from_raw(pid as i32);
setpriority_process(pid, nice_value).map_err(|_| USimpleError::new(0, "Permission Denied"))
}

#[cfg(unix)]
Expand Down
17 changes: 4 additions & 13 deletions src/uu/top/src/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,11 @@ fn pr(_pid: u32, _stat: Stat) -> Box<dyn Column> {

#[cfg(not(target_os = "windows"))]
fn get_nice(pid: u32) -> i32 {
use nix::errno::Errno;
use uucore::libc::{getpriority, PRIO_PROCESS};
use rustix::process::{getpriority_process, Pid};

// this is nice value, not priority value
let result = unsafe { getpriority(PRIO_PROCESS, pid) };

let result = if Errno::last() == Errno::UnknownErrno {
result
} else {
Errno::clear();
0
};

result as i32
let pid = Pid::from_raw(pid as i32);
getpriority_process(pid).unwrap_or(0)
}

#[cfg(not(target_os = "windows"))]
Expand Down Expand Up @@ -381,7 +372,7 @@ fn shr(pid: u32, _stat: Stat) -> Box<dyn Column> {
let content = read_to_string(file).unwrap();
let values = content.split_whitespace();
if let Some(shared) = values.collect::<Vec<_>>().get(2) {
let page_size = unsafe { uucore::libc::sysconf(uucore::libc::_SC_PAGESIZE) };
let page_size = rustix::param::page_size();
MemValue::new_boxed(shared.parse::<u64>().unwrap() * page_size as u64)
} else {
MemValue::new_boxed(0)
Expand Down
Loading