mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 20:17:42 +00:00
Make it possible for a process to switch controlling terminals.
Via the TIOCSCTTY and TIOCNOTTY ioctls.
This commit is contained in:
parent
10308c6434
commit
49b63281a0
6 changed files with 31 additions and 4 deletions
|
@ -206,6 +206,7 @@ public:
|
||||||
static int reap(Process&) WARN_UNUSED_RESULT;
|
static int reap(Process&) WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
const TTY* tty() const { return m_tty; }
|
const TTY* tty() const { return m_tty; }
|
||||||
|
void set_tty(TTY* tty) { m_tty = tty; }
|
||||||
|
|
||||||
size_t regionCount() const { return m_regions.size(); }
|
size_t regionCount() const { return m_regions.size(); }
|
||||||
const Vector<RetainPtr<Region>>& regions() const { return m_regions; }
|
const Vector<RetainPtr<Region>>& regions() const { return m_regions; }
|
||||||
|
|
|
@ -5,6 +5,7 @@ SlavePTY::SlavePTY(unsigned index)
|
||||||
: TTY(11, index)
|
: TTY(11, index)
|
||||||
, m_index(index)
|
, m_index(index)
|
||||||
{
|
{
|
||||||
|
set_size(80, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
SlavePTY::~SlavePTY()
|
SlavePTY::~SlavePTY()
|
||||||
|
|
|
@ -107,7 +107,7 @@ int TTY::ioctl(Process& process, unsigned request, unsigned arg)
|
||||||
Unix::termios* tp;
|
Unix::termios* tp;
|
||||||
Unix::winsize* ws;
|
Unix::winsize* ws;
|
||||||
|
|
||||||
if (process.tty() != this)
|
if (process.tty() && process.tty() != this)
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
switch (request) {
|
switch (request) {
|
||||||
case TIOCGPGRP:
|
case TIOCGPGRP:
|
||||||
|
@ -140,6 +140,12 @@ int TTY::ioctl(Process& process, unsigned request, unsigned arg)
|
||||||
ws->ws_row = m_rows;
|
ws->ws_row = m_rows;
|
||||||
ws->ws_col = m_columns;
|
ws->ws_col = m_columns;
|
||||||
return 0;
|
return 0;
|
||||||
|
case TIOCSCTTY:
|
||||||
|
process.set_tty(this);
|
||||||
|
return 0;
|
||||||
|
case TIOCNOTTY:
|
||||||
|
process.set_tty(nullptr);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -8,5 +8,7 @@ enum IOCtlNumber {
|
||||||
TCSETSW,
|
TCSETSW,
|
||||||
TCSETSF,
|
TCSETSF,
|
||||||
TIOCGWINSZ,
|
TIOCGWINSZ,
|
||||||
|
TIOCSCTTY,
|
||||||
|
TIOCNOTTY,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <Widgets/Font.h>
|
#include <Widgets/Font.h>
|
||||||
#include <Widgets/GraphicsBitmap.h>
|
#include <Widgets/GraphicsBitmap.h>
|
||||||
#include <Widgets/Painter.h>
|
#include <Widgets/Painter.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <gui.h>
|
#include <gui.h>
|
||||||
#include "Terminal.h"
|
#include "Terminal.h"
|
||||||
|
|
||||||
|
@ -20,9 +21,15 @@ static void make_shell(int ptm_fd)
|
||||||
perror("ptsname");
|
perror("ptsname");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
int rc = 0;
|
||||||
close(ptm_fd);
|
close(ptm_fd);
|
||||||
int pts_fd = open(tty_name, O_RDWR);
|
int pts_fd = open(tty_name, O_RDWR);
|
||||||
dbgprintf("*** In child (%d), opening slave pty %s, pts_fd=%d\n", getpid(), tty_name, pts_fd);
|
dbgprintf("*** In child (%d), opening slave pty %s, pts_fd=%d\n", getpid(), tty_name, pts_fd);
|
||||||
|
rc = ioctl(0, TIOCNOTTY);
|
||||||
|
if (rc < 0) {
|
||||||
|
perror("ioctl(TIOCNOTTY)");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
close(0);
|
close(0);
|
||||||
close(1);
|
close(1);
|
||||||
close(2);
|
close(2);
|
||||||
|
@ -30,7 +37,12 @@ static void make_shell(int ptm_fd)
|
||||||
dup2(pts_fd, 1);
|
dup2(pts_fd, 1);
|
||||||
dup2(pts_fd, 2);
|
dup2(pts_fd, 2);
|
||||||
close(pts_fd);
|
close(pts_fd);
|
||||||
int rc = execve("/bin/sh", nullptr, nullptr);
|
rc = ioctl(0, TIOCSCTTY);
|
||||||
|
if (rc < 0) {
|
||||||
|
perror("ioctl(TIOCSCTTY)");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
rc = execve("/bin/sh", nullptr, nullptr);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror("execve");
|
perror("execve");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -7,8 +8,12 @@ int main(int argc, char** argv)
|
||||||
(void) argv;
|
(void) argv;
|
||||||
|
|
||||||
struct winsize ws;
|
struct winsize ws;
|
||||||
ioctl(0, TIOCGWINSZ, &ws);
|
int rc = ioctl(0, TIOCGWINSZ, &ws);
|
||||||
printf("Terminal is %ux%u\n", ws.ws_col, ws.ws_row);
|
if (rc < 0) {
|
||||||
|
perror("ioctl(TIOCGWINSZ)");
|
||||||
|
}
|
||||||
|
printf("TTY is %s\n", ttyname(0));
|
||||||
|
printf("Terminal size is %ux%u\n", ws.ws_col, ws.ws_row);
|
||||||
|
|
||||||
printf("Counting to 100000: \033[s");
|
printf("Counting to 100000: \033[s");
|
||||||
for (unsigned i = 0; i <= 100000; ++i) {
|
for (unsigned i = 0; i <= 100000; ++i) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue