Skip to content

Commit a5ad168

Browse files
pgrep: use safe wrappers for libc functions
1 parent 6a163ad commit a5ad168

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
@@ -11,7 +11,7 @@ use std::{collections::HashSet, io};
1111
use clap::{arg, Arg, ArgAction, ArgMatches};
1212
use regex::Regex;
1313
#[cfg(unix)]
14-
use uucore::libc::{getpgrp, getsid};
14+
use uucore::process::{getpgrp, getsid};
1515
#[cfg(unix)]
1616
use uucore::{
1717
display::Quotable,
@@ -82,14 +82,8 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
8282
.get_many::<u32>("group")
8383
.map(|ids| ids.cloned().collect()),
8484
pgroup: matches.get_many::<u64>("pgroup").map(|xs| {
85-
xs.map(|pg| {
86-
if *pg == 0 {
87-
unsafe { getpgrp() as u64 }
88-
} else {
89-
*pg
90-
}
91-
})
92-
.collect()
85+
xs.map(|pg| if *pg == 0 { getpgrp() as u64 } else { *pg })
86+
.collect()
9387
}),
9488
session: matches.get_many::<u64>("session").map(|xs| {
9589
xs.map(|sid| {
@@ -343,7 +337,7 @@ pub fn grp2gid(_name: &str) -> io::Result<u32> {
343337
///
344338
/// Dummy implementation for unsupported platforms.
345339
#[cfg(not(unix))]
346-
pub unsafe fn getpgrp() -> u32 {
340+
pub fn getpgrp() -> u32 {
347341
panic!("unsupported on this platform");
348342
}
349343

0 commit comments

Comments
 (0)