mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-20 13:06:33 +00:00
Handle negative P(G)IDs via cast_(un)signed
This commit is contained in:
committed by
Jianfeng Jiang
parent
d3e4f175cd
commit
50ba735e96
@ -12,6 +12,10 @@ pub fn sys_setpgid(pid: Pid, pgid: Pgid, ctx: &Context) -> Result<SyscallReturn>
|
||||
// The documentation quoted below is from
|
||||
// <https://www.man7.org/linux/man-pages/man2/setpgid.2.html>.
|
||||
|
||||
if pid.cast_signed() < 0 || pgid.cast_signed() < 0 {
|
||||
return_errno_with_message!(Errno::EINVAL, "negative PIDs or PGIDs are not valid");
|
||||
}
|
||||
|
||||
// "If `pid` is zero, then the process ID of the calling process is used."
|
||||
let pid = if pid == 0 { current.pid() } else { pid };
|
||||
// "If `pgid` is zero, then the PGID of the process specified by `pid` is made the same as its
|
||||
|
@ -15,14 +15,16 @@ pub fn sys_waitid(
|
||||
ctx: &Context,
|
||||
) -> Result<SyscallReturn> {
|
||||
// FIXME: what does infoq and rusage use for?
|
||||
let process_filter = ProcessFilter::from_which_and_id(which, upid)?;
|
||||
let process_filter = ProcessFilter::from_which_and_id(which, upid as _)?;
|
||||
let wait_options = WaitOptions::from_bits(options as u32)
|
||||
.ok_or(Error::with_message(Errno::EINVAL, "invalid options"))?;
|
||||
|
||||
let waited_process =
|
||||
wait_child_exit(process_filter, wait_options, ctx).map_err(|err| match err.error() {
|
||||
Errno::EINTR => Error::new(Errno::ERESTARTSYS),
|
||||
_ => err,
|
||||
})?;
|
||||
|
||||
let pid = waited_process.map_or(0, |process| process.pid());
|
||||
Ok(SyscallReturn::Return(pid as _))
|
||||
}
|
||||
|
Reference in New Issue
Block a user