forked from Bananymous/banan-os
Kernel: Implement SYS_GET_PID and SYS_TCSETPGID
we don't have consept of process groups yet
This commit is contained in:
parent
1ef0534b69
commit
f6ee4b3496
|
@ -104,6 +104,8 @@ namespace Kernel
|
||||||
BAN::ErrorOr<long> sys_raise(int signal);
|
BAN::ErrorOr<long> sys_raise(int signal);
|
||||||
static BAN::ErrorOr<long> sys_kill(pid_t pid, 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_termid(char*) const;
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_clock_gettime(clockid_t, timespec*) const;
|
BAN::ErrorOr<long> sys_clock_gettime(clockid_t, timespec*) const;
|
||||||
|
|
|
@ -848,10 +848,31 @@ namespace Kernel
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t Process::foreground_pid()
|
BAN::ErrorOr<long> Process::sys_tcsetpgrp(int fd, pid_t pgid)
|
||||||
{
|
{
|
||||||
ASSERT(s_foreground_pid);
|
LockGuard _(m_lock);
|
||||||
return s_foreground_pid;
|
|
||||||
|
// 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)
|
BAN::ErrorOr<long> Process::sys_setuid(uid_t uid)
|
||||||
|
|
|
@ -160,6 +160,12 @@ namespace Kernel
|
||||||
case SYS_SIGNAL_DONE:
|
case SYS_SIGNAL_DONE:
|
||||||
// Handled above
|
// Handled above
|
||||||
ASSERT_NOT_REACHED();
|
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:
|
default:
|
||||||
dwarnln("Unknown syscall {}", syscall);
|
dwarnln("Unknown syscall {}", syscall);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -45,6 +45,8 @@ __BEGIN_DECLS
|
||||||
#define SYS_KILL 38
|
#define SYS_KILL 38
|
||||||
#define SYS_SIGNAL 39
|
#define SYS_SIGNAL 39
|
||||||
#define SYS_SIGNAL_DONE 40
|
#define SYS_SIGNAL_DONE 40
|
||||||
|
#define SYS_TCSETPGRP 41
|
||||||
|
#define SYS_GET_PID 42
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -286,6 +286,18 @@ long syscall(long syscall, ...)
|
||||||
ret = Kernel::syscall(SYS_SIGNAL, signal, (uintptr_t)handler);
|
ret = Kernel::syscall(SYS_SIGNAL, signal, (uintptr_t)handler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SYS_TCSETPGRP:
|
||||||
|
{
|
||||||
|
int fd = va_arg(args, int);
|
||||||
|
pid_t pgrp = va_arg(args, pid_t);
|
||||||
|
ret = Kernel::syscall(SYS_TCSETPGRP, fd, pgrp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SYS_GET_PID:
|
||||||
|
{
|
||||||
|
ret = Kernel::syscall(SYS_GET_PID);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SYS_SIGNAL_DONE:
|
case SYS_SIGNAL_DONE:
|
||||||
// Should not be called by an user
|
// Should not be called by an user
|
||||||
// fall through
|
// fall through
|
||||||
|
@ -438,6 +450,11 @@ int chdir(const char* path)
|
||||||
return syscall(SYS_SET_PWD, path);
|
return syscall(SYS_SET_PWD, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t getpid(void)
|
||||||
|
{
|
||||||
|
return syscall(SYS_GET_PID);
|
||||||
|
}
|
||||||
|
|
||||||
uid_t getuid(void)
|
uid_t getuid(void)
|
||||||
{
|
{
|
||||||
return syscall(SYS_GET_UID);
|
return syscall(SYS_GET_UID);
|
||||||
|
@ -487,3 +504,8 @@ int setregid(gid_t rgid, gid_t egid)
|
||||||
{
|
{
|
||||||
return syscall(SYS_SET_REGID, rgid, egid);
|
return syscall(SYS_SET_REGID, rgid, egid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tcsetpgrp(int fildes, pid_t pgid_id)
|
||||||
|
{
|
||||||
|
return syscall(SYS_TCSETPGRP, fildes, pgid_id);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue