mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:27:35 +00:00
HackStudio: Add TerminalWrapper::kill_running_command()
Also put our child process into a new process group in order to be able to kill it along with its own children.
This commit is contained in:
parent
cd11a8597a
commit
8484635920
2 changed files with 14 additions and 0 deletions
|
@ -6,9 +6,11 @@
|
||||||
#include <LibGUI/GMessageBox.h>
|
#include <LibGUI/GMessageBox.h>
|
||||||
#include <LibVT/TerminalWidget.h>
|
#include <LibVT/TerminalWidget.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -54,6 +56,9 @@ void TerminalWrapper::run_command(const String& command)
|
||||||
|
|
||||||
m_pid = fork();
|
m_pid = fork();
|
||||||
if (m_pid == 0) {
|
if (m_pid == 0) {
|
||||||
|
// Create a new process group.
|
||||||
|
setsid();
|
||||||
|
|
||||||
const char* tty_name = ptsname(ptm_fd);
|
const char* tty_name = ptsname(ptm_fd);
|
||||||
if (!tty_name) {
|
if (!tty_name) {
|
||||||
perror("ptsname");
|
perror("ptsname");
|
||||||
|
@ -116,6 +121,14 @@ void TerminalWrapper::run_command(const String& command)
|
||||||
m_process_state_widget->set_tty_fd(ptm_fd);
|
m_process_state_widget->set_tty_fd(ptm_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TerminalWrapper::kill_running_command()
|
||||||
|
{
|
||||||
|
ASSERT(m_pid != -1);
|
||||||
|
|
||||||
|
// Kill our child process and its whole process group.
|
||||||
|
(void)killpg(m_pid, SIGTERM);
|
||||||
|
}
|
||||||
|
|
||||||
TerminalWrapper::TerminalWrapper(GWidget* parent)
|
TerminalWrapper::TerminalWrapper(GWidget* parent)
|
||||||
: GWidget(parent)
|
: GWidget(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@ public:
|
||||||
virtual ~TerminalWrapper() override;
|
virtual ~TerminalWrapper() override;
|
||||||
|
|
||||||
void run_command(const String&);
|
void run_command(const String&);
|
||||||
|
void kill_running_command();
|
||||||
|
|
||||||
Function<void()> on_command_exit;
|
Function<void()> on_command_exit;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue