diff --git a/src/aero_kernel/src/syscall/process.rs b/src/aero_kernel/src/syscall/process.rs index f9a41c2fd14..97996c8ced5 100644 --- a/src/aero_kernel/src/syscall/process.rs +++ b/src/aero_kernel/src/syscall/process.rs @@ -17,7 +17,6 @@ use aero_syscall::signal::{SigAction, SigProcMask}; use aero_syscall::*; -use alloc::sync::Arc; use spin::{Mutex, Once}; use crate::acpi::aml; @@ -28,7 +27,7 @@ use crate::mem::paging::VirtAddr; use crate::userland::scheduler::{self, ExitStatus}; use crate::userland::signals::SignalEntry; use crate::userland::task::sessions::SESSIONS; -use crate::userland::task::{Task, TaskId}; +use crate::userland::task::TaskId; use crate::utils::sync::IrqGuard; static HOSTNAME: Once> = Once::new(); @@ -363,31 +362,43 @@ pub fn shutdown() -> Result { unreachable!("aml: failed to shutdown (enter state S5)") } -fn find_task_by_pid(pid: usize) -> Result> { - let current_task = scheduler::get_scheduler().current_task(); +#[syscall] +pub fn getpgid(pid: usize) -> Result { + let current_task = scheduler::current_thread(); // If `pid` is 0, the process ID of the calling process is used. - if pid == 0 || pid == current_task.pid().as_usize() { - Ok(current_task) + let task = if pid == 0 || pid == current_task.pid().as_usize() { + current_task } else { scheduler::get_scheduler() .find_task(TaskId::new(pid)) - .ok_or(SyscallError::ESRCH) - } -} + .ok_or(SyscallError::ESRCH)? + }; -#[syscall] -pub fn getpgid(pid: usize) -> Result { - let task = find_task_by_pid(pid)?; let group = SESSIONS.find_group(&task).unwrap(); - Ok(group.id()) } #[syscall] pub fn setpgid(pid: usize, pgid: usize) -> Result { - let current_task = scheduler::get_scheduler().current_task(); - let task = find_task_by_pid(pid)?; + let current_task = scheduler::current_thread(); + let task = if pid == 0 || pid == current_task.pid().as_usize() { + current_task.clone() + } else { + let task = scheduler::get_scheduler() + .find_task(TaskId::new(pid)) + .ok_or(SyscallError::ESRCH)?; + + if let Some(parent) = task.get_parent() { + if parent.tid() != current_task.tid() { + return Err(SyscallError::EPERM); + } + } else { + return Err(SyscallError::EPERM); + } + + task + }; if task.is_session_leader() || !task.is_process_leader() @@ -396,16 +407,6 @@ pub fn setpgid(pid: usize, pgid: usize) -> Result { return Err(SyscallError::EPERM); } - if let Some(parent) = task.get_parent() { - if parent.tid() != current_task.tid() { - return Err(SyscallError::EPERM); - } - } else { - return Err(SyscallError::EPERM); - } - - // If `pgid` is 0, the process ID of the process specified by the `pid` argument shall - // be used. log::error!("setpgid: is a stub! (pid={pid} pgid={pgid})"); Ok(0) }