Skip to content
Open
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
16 changes: 5 additions & 11 deletions src/uu/pgrep/src/process_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,19 +91,13 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
.get_many::<u32>("group")
.map(|ids| ids.cloned().collect()),
pgroup: matches.get_many::<u64>("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::<u64>("session").map(|xs| {
xs.map(|sid| {
if *sid == 0 {
unsafe { getsid(0) as u64 }
getsid(0).unwrap() as u64
} else {
*sid
}
Expand Down Expand Up @@ -445,7 +439,7 @@ pub fn grp2gid(_name: &str) -> io::Result<u32> {
///
/// Dummy implementation for unsupported platforms.
#[cfg(not(unix))]
pub unsafe fn getpgrp() -> u32 {
pub fn getpgrp() -> u32 {
panic!("unsupported on this platform");
}

Expand Down
25 changes: 2 additions & 23 deletions src/uu/ps/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32> {
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<i32> {
Some(0)
}
use uucore::process::getsid;

// Guessing it matches the current terminal
pub(crate) fn basic_collector(
Expand Down Expand Up @@ -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());
Expand Down
Loading