Skip to content

pgrep: use safe wrappers for libc functions #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 4 additions & 10 deletions src/uu/pgrep/src/process_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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 @@ -82,14 +82,8 @@ 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| {
Expand Down Expand Up @@ -343,7 +337,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
Loading