mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +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
|
@ -8,6 +8,7 @@
|
|||
#include <Widgets/Font.h>
|
||||
#include <Widgets/GraphicsBitmap.h>
|
||||
#include <Widgets/Painter.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <gui.h>
|
||||
#include "Terminal.h"
|
||||
|
||||
|
@ -20,9 +21,15 @@ static void make_shell(int ptm_fd)
|
|||
perror("ptsname");
|
||||
exit(1);
|
||||
}
|
||||
int rc = 0;
|
||||
close(ptm_fd);
|
||||
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);
|
||||
rc = ioctl(0, TIOCNOTTY);
|
||||
if (rc < 0) {
|
||||
perror("ioctl(TIOCNOTTY)");
|
||||
exit(1);
|
||||
}
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
|
@ -30,7 +37,12 @@ static void make_shell(int ptm_fd)
|
|||
dup2(pts_fd, 1);
|
||||
dup2(pts_fd, 2);
|
||||
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) {
|
||||
perror("execve");
|
||||
exit(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue