1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:38:10 +00:00

Kernel: Distinguish between new and old process groups with equal pgids

This does not add any behaviour change to the processes, but it ties a
TTY to an active process group via TIOCSPGRP, and returns the TTY to the
kernel when all processes in the process group die.
Also makes the TTY keep a link to the original controlling process' parent (for
SIGCHLD) instead of the process itself.
This commit is contained in:
AnotherTest 2020-08-15 23:43:19 +04:30 committed by Andreas Kling
parent cf18bff72a
commit 688e54eac7
9 changed files with 176 additions and 23 deletions

View file

@ -155,10 +155,8 @@ void TTY::emit(u8 ch)
if (ch == m_termios.c_cc[VSUSP]) {
dbg() << tty_name() << ": VSUSP pressed!";
generate_signal(SIGTSTP);
if (m_process) {
if (auto parent = Process::from_pid(m_process->ppid()))
(void)parent->send_signal(SIGCHLD, m_process);
}
if (m_original_process_parent)
(void)m_original_process_parent->send_signal(SIGCHLD, nullptr);
// TODO: Else send it to the session leader maybe?
return;
}
@ -310,13 +308,27 @@ int TTY::ioctl(FileDescription&, unsigned request, FlatPtr arg)
if (pgid <= 0)
return -EINVAL;
InterruptDisabler disabler;
auto process = Process::from_pid(pgid.value());
auto process_group = ProcessGroup::from_pgid(pgid);
// Disallow setting a nonexistent PGID.
if (!process_group)
return -EINVAL;
auto process = Process::from_pid(ProcessID(pgid.value()));
SessionID new_sid = process ? process->sid() : Process::get_sid_from_pgid(pgid);
if (!new_sid || new_sid != current_process.sid())
return -EPERM;
if (process && pgid != process->pgid())
return -EPERM;
m_process = process ? process->make_weak_ptr() : WeakPtr<Process>();
m_pg = process_group->make_weak_ptr();
if (process) {
if (auto parent = Process::from_pid(process->ppid())) {
m_original_process_parent = parent->make_weak_ptr();
return 0;
}
}
m_original_process_parent = nullptr;
return 0;
}
case TCGETS: {
@ -392,10 +404,4 @@ void TTY::hang_up()
{
generate_signal(SIGHUP);
}
ProcessGroupID TTY::pgid() const
{
return m_process ? m_process->pgid() : 0;
}
}