diff --git a/src/uu/pgrep/src/process_matcher.rs b/src/uu/pgrep/src/process_matcher.rs index 40936699..857889a7 100644 --- a/src/uu/pgrep/src/process_matcher.rs +++ b/src/uu/pgrep/src/process_matcher.rs @@ -13,7 +13,7 @@ use std::{collections::HashSet, io}; use clap::{arg, Arg, ArgAction, ArgMatches}; use regex::Regex; #[cfg(unix)] -use uucore::libc::{getpgrp, getsid}; +use uucore::process::{getpgrp, getsid}; #[cfg(unix)] use uucore::{ display::Quotable, @@ -91,19 +91,13 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult { .get_many::("group") .map(|ids| ids.cloned().collect()), pgroup: matches.get_many::("pgroup").map(|xs| { - xs.map(|pg| { - if *pg == 0 { - unsafe { getpgrp() as u64 } - } else { - *pg - } - }) - .collect() + xs.map(|pg| if *pg == 0 { getpgrp() as u64 } else { *pg }) + .collect() }), session: matches.get_many::("session").map(|xs| { xs.map(|sid| { if *sid == 0 { - unsafe { getsid(0) as u64 } + getsid(0).unwrap() as u64 } else { *sid } @@ -445,7 +439,7 @@ pub fn grp2gid(_name: &str) -> io::Result { /// /// Dummy implementation for unsupported platforms. #[cfg(not(unix))] -pub unsafe fn getpgrp() -> u32 { +pub fn getpgrp() -> u32 { panic!("unsupported on this platform"); } diff --git a/src/uu/ps/src/collector.rs b/src/uu/ps/src/collector.rs index 2649a417..1ea8ff20 100644 --- a/src/uu/ps/src/collector.rs +++ b/src/uu/ps/src/collector.rs @@ -4,30 +4,9 @@ // file that was distributed with this source code. use clap::ArgMatches; -#[cfg(target_family = "unix")] -use nix::errno::Errno; use std::{cell::RefCell, path::PathBuf, rc::Rc, str::FromStr}; use uu_pgrep::process::{ProcessInformation, Teletype}; - -// TODO: Temporary add to this file, this function will add to uucore. -#[cfg(not(target_os = "redox"))] -#[cfg(target_family = "unix")] -fn getsid(pid: i32) -> Option { - unsafe { - let result = libc::getsid(pid); - if Errno::last() == Errno::UnknownErrno { - Some(result) - } else { - None - } - } -} - -// TODO: Temporary add to this file, this function will add to uucore. -#[cfg(target_family = "windows")] -fn getsid(_pid: i32) -> Option { - Some(0) -} +use uucore::process::getsid; // Guessing it matches the current terminal pub(crate) fn basic_collector( @@ -96,7 +75,7 @@ pub(crate) fn session_collector( for it in proc_snapshot { let pid = it.borrow().pid; - if let Some(sid) = getsid(pid as i32) { + if let Ok(sid) = getsid(pid as i32) { // Check is session leader if sid != (pid as i32) && tty(it) != Teletype::Unknown { result.push(it.clone());