1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:07:34 +00:00

Add tcsetpgrp()+tcgetpgrp().

One more step on the path to being able to ^C a runaway process. :^)
This commit is contained in:
Andreas Kling 2018-11-02 13:14:25 +01:00
parent d8f0dd6f3b
commit 621217ffeb
11 changed files with 72 additions and 4 deletions

View file

@ -277,10 +277,11 @@ ByteBuffer procfs$summary()
auto processes = Process::allProcesses();
auto buffer = ByteBuffer::createUninitialized(processes.size() * 256);
char* ptr = (char*)buffer.pointer();
ptr += ksprintf(ptr, "PID PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n");
ptr += ksprintf(ptr, "PID TPG PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n");
for (auto* process : processes) {
ptr += ksprintf(ptr, "% 3u % 3u % 3u % 4u % 8s % 3u % 9u % 3u % 4s %s\n",
ptr += ksprintf(ptr, "% 3u % 3u % 3u % 3u % 4u % 8s % 3u % 9u % 3u % 4s %s\n",
process->pid(),
process->tty() ? process->tty()->pgid() : 0,
process->pgid(),
process->sid(),
process->uid(),

View file

@ -1249,3 +1249,34 @@ int Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
process->m_pgid = new_pgid;
return 0;
}
pid_t Process::sys$tcgetpgrp(int fd)
{
auto* handle = fileHandleIfExists(fd);
if (!handle)
return -EBADF;
if (!handle->isTTY())
return -ENOTTY;
auto& tty = *handle->tty();
if (&tty != m_tty)
return -ENOTTY;
return tty.pgid();
}
int Process::sys$tcsetpgrp(int fd, pid_t pgid)
{
if (pgid < 0)
return -EINVAL;
if (get_sid_from_pgid(pgid) != m_sid)
return -EINVAL;
auto* handle = fileHandleIfExists(fd);
if (!handle)
return -EBADF;
if (!handle->isTTY())
return -ENOTTY;
auto& tty = *handle->tty();
if (&tty != m_tty)
return -ENOTTY;
tty.set_pgid(pgid);
return 0;
}

View file

@ -86,6 +86,8 @@ public:
int sys$setpgid(pid_t pid, pid_t pgid);
pid_t sys$getpgrp();
pid_t sys$getpgid(pid_t);
pid_t sys$tcgetpgrp(int fd);
int sys$tcsetpgrp(int fd, pid_t pgid);
uid_t sys$getuid();
gid_t sys$getgid();
pid_t sys$getpid();

View file

@ -124,6 +124,10 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
return current->sys$getpgid((pid_t)arg1);
case Syscall::PosixGetpgrp:
return current->sys$getpgrp();
case Syscall::PosixTcgetpgrp:
return current->sys$tcgetpgrp((int)arg1);
case Syscall::PosixTcsetpgrp:
return current->sys$tcsetpgrp((int)arg1, (pid_t)arg2);
default:
kprintf("<%u> int0x80: Unknown function %x requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3);
break;

View file

@ -45,6 +45,8 @@ enum Function {
PosixGetpgid = 0x2013,
PosixSetpgid = 0x2014,
PosixGetpgrp = 0x2015,
PosixTcsetpgrp = 0x2016,
PosixTcgetpgrp = 0x2017,
};
void initialize();

View file

@ -12,6 +12,9 @@ public:
virtual String ttyName() const = 0;
void set_pgid(pid_t pgid) { m_pgid = pgid; }
pid_t pgid() const { return m_pgid; }
protected:
virtual bool isTTY() const final { return true; }
@ -22,5 +25,6 @@ protected:
private:
Vector<byte> m_buffer;
pid_t m_pgid { 0 };
};