mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-20 13:06:33 +00:00
Refactor and test set{pgid,sid}
This commit is contained in:
committed by
Jianfeng Jiang
parent
4f2ce276a0
commit
7e4509df9c
@ -3,35 +3,24 @@
|
||||
use super::SyscallReturn;
|
||||
use crate::{
|
||||
prelude::*,
|
||||
process::{process_table, Pgid, Pid},
|
||||
process::{Pgid, Pid},
|
||||
};
|
||||
|
||||
pub fn sys_setpgid(pid: Pid, pgid: Pgid, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let current = ctx.process;
|
||||
// if pid is 0, pid should be the pid of current process
|
||||
|
||||
// The documentation quoted below is from
|
||||
// <https://www.man7.org/linux/man-pages/man2/setpgid.2.html>.
|
||||
|
||||
// "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 0, pgid should be pid
|
||||
// "If `pgid` is zero, then the PGID of the process specified by `pid` is made the same as its
|
||||
// process ID."
|
||||
let pgid = if pgid == 0 { pid } else { pgid };
|
||||
|
||||
debug!("pid = {}, pgid = {}", pid, pgid);
|
||||
|
||||
if pid != current.pid() && !current.has_child(&pid) {
|
||||
return_errno_with_message!(
|
||||
Errno::ESRCH,
|
||||
"cannot set pgid for process other than current or children of current"
|
||||
);
|
||||
}
|
||||
// FIXME: If pid is child process of current and already calls execve, should return error.
|
||||
// How can we determine a child process has called execve?
|
||||
|
||||
// only can move process to an existing group or self
|
||||
if pgid != pid && !process_table::contain_process_group(&pgid) {
|
||||
return_errno_with_message!(Errno::EPERM, "process group must exist");
|
||||
}
|
||||
|
||||
let process = process_table::get_process(pid)
|
||||
.ok_or(Error::with_message(Errno::ESRCH, "process does not exist"))?;
|
||||
|
||||
process.to_other_group(pgid)?;
|
||||
current.move_process_to_group(pid, pgid)?;
|
||||
|
||||
Ok(SyscallReturn::Return(0))
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ use super::SyscallReturn;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn sys_setsid(_ctx: &Context) -> Result<SyscallReturn> {
|
||||
let current = current!();
|
||||
let session = current.to_new_session()?;
|
||||
let sid = current!().to_new_session()?;
|
||||
|
||||
Ok(SyscallReturn::Return(session.sid() as _))
|
||||
Ok(SyscallReturn::Return(sid as _))
|
||||
}
|
||||
|
Reference in New Issue
Block a user