Skip to content

Commit 8258341

Browse files
pgrep: use safe wrappers for libc functions
1 parent 08af5de commit 8258341

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/uu/pgrep/src/process_matcher.rs

Lines changed: 5 additions & 11 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,
@@ -91,19 +91,13 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
9191
.get_many::<u32>("group")
9292
.map(|ids| ids.cloned().collect()),
9393
pgroup: matches.get_many::<u64>("pgroup").map(|xs| {
94-
xs.map(|pg| {
95-
if *pg == 0 {
96-
unsafe { getpgrp() as u64 }
97-
} else {
98-
*pg
99-
}
100-
})
101-
.collect()
94+
xs.map(|pg| if *pg == 0 { getpgrp() as u64 } else { *pg })
95+
.collect()
10296
}),
10397
session: matches.get_many::<u64>("session").map(|xs| {
10498
xs.map(|sid| {
10599
if *sid == 0 {
106-
unsafe { getsid(0) as u64 }
100+
getsid(0).unwrap() as u64
107101
} else {
108102
*sid
109103
}
@@ -445,7 +439,7 @@ pub fn grp2gid(_name: &str) -> io::Result<u32> {
445439
///
446440
/// Dummy implementation for unsupported platforms.
447441
#[cfg(not(unix))]
448-
pub unsafe fn getpgrp() -> u32 {
442+
pub fn getpgrp() -> u32 {
449443
panic!("unsupported on this platform");
450444
}
451445

0 commit comments

Comments
 (0)