Skip to content

Commit 479f379

Browse files
eduardorittnercakebaker
authored andcommitted
pgrep: use safe wrappers for libc functions
1 parent fa83319 commit 479f379

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/uu/pgrep/src/process_matcher.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{collections::HashSet, io};
1313
use clap::{arg, Arg, ArgAction, ArgMatches};
1414
use regex::Regex;
1515
#[cfg(unix)]
16-
use uucore::libc::{getpgrp, getsid};
16+
use uucore::process::{getpgrp, getsid};
1717
#[cfg(unix)]
1818
use uucore::{
1919
display::Quotable,
@@ -89,14 +89,8 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
8989
.get_many::<u32>("group")
9090
.map(|ids| ids.cloned().collect()),
9191
pgroup: matches.get_many::<u64>("pgroup").map(|xs| {
92-
xs.map(|pg| {
93-
if *pg == 0 {
94-
unsafe { getpgrp() as u64 }
95-
} else {
96-
*pg
97-
}
98-
})
99-
.collect()
92+
xs.map(|pg| if *pg == 0 { getpgrp() as u64 } else { *pg })
93+
.collect()
10094
}),
10195
session: matches.get_many::<u64>("session").map(|xs| {
10296
xs.map(|sid| {
@@ -390,7 +384,7 @@ pub fn grp2gid(_name: &str) -> io::Result<u32> {
390384
///
391385
/// Dummy implementation for unsupported platforms.
392386
#[cfg(not(unix))]
393-
pub unsafe fn getpgrp() -> u32 {
387+
pub fn getpgrp() -> u32 {
394388
panic!("unsupported on this platform");
395389
}
396390

0 commit comments

Comments
 (0)