Kernel: Implement SYS_GET_PID and SYS_TCSETPGID
we don't have consept of process groups yet
This commit is contained in:
@@ -104,6 +104,8 @@ namespace Kernel
|
||||
BAN::ErrorOr<long> sys_raise(int signal);
|
||||
static BAN::ErrorOr<long> sys_kill(pid_t pid, int signal);
|
||||
|
||||
BAN::ErrorOr<long> sys_tcsetpgrp(int fd, pid_t pgid);
|
||||
|
||||
BAN::ErrorOr<long> sys_termid(char*) const;
|
||||
|
||||
BAN::ErrorOr<long> sys_clock_gettime(clockid_t, timespec*) const;
|
||||
|
||||
@@ -848,10 +848,31 @@ namespace Kernel
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t Process::foreground_pid()
|
||||
BAN::ErrorOr<long> Process::sys_tcsetpgrp(int fd, pid_t pgid)
|
||||
{
|
||||
ASSERT(s_foreground_pid);
|
||||
return s_foreground_pid;
|
||||
LockGuard _(m_lock);
|
||||
|
||||
// FIXME: validate the inode
|
||||
auto inode = TRY(m_open_file_descriptors.inode_of(fd));
|
||||
if (!inode->is_tty())
|
||||
return BAN::Error::from_errno(ENOTTY);
|
||||
|
||||
// FIXME: use process groups instead of process ids
|
||||
// FIXME: return values
|
||||
|
||||
LockGuard process_guard(s_process_lock);
|
||||
for (auto* process : s_processes)
|
||||
{
|
||||
if (process->pid() == pgid)
|
||||
{
|
||||
if (!process->is_userspace())
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
((TTY*)inode.ptr())->set_foreground_process(pgid);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return BAN::Error::from_errno(EPERM);
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_setuid(uid_t uid)
|
||||
|
||||
@@ -160,6 +160,12 @@ namespace Kernel
|
||||
case SYS_SIGNAL_DONE:
|
||||
// Handled above
|
||||
ASSERT_NOT_REACHED();
|
||||
case SYS_TCSETPGRP:
|
||||
ret = Process::current().sys_tcsetpgrp((int)arg1, (pid_t)arg2);
|
||||
break;
|
||||
case SYS_GET_PID:
|
||||
ret = Process::current().pid();
|
||||
break;
|
||||
default:
|
||||
dwarnln("Unknown syscall {}", syscall);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user