1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:58:11 +00:00

Add basic PTY support.

For now, there are four hard-coded PTYs: /dev/pt{m,s}[0123]
Use this in the Terminal to open a pty pair and spawn a shell.
This commit is contained in:
Andreas Kling 2019-01-15 06:30:19 +01:00
parent ecb4ab0943
commit 2f74c2f430
21 changed files with 287 additions and 10 deletions

View file

@ -19,6 +19,7 @@
#include "FIFO.h"
#include "KSyms.h"
#include <Widgets/Window.h>
#include "MasterPTY.h"
//#define DEBUG_IO
//#define TASK_DEBUG
@ -989,6 +990,23 @@ int Process::sys$ttyname_r(int fd, char* buffer, size_t size)
return 0;
}
int Process::sys$ptsname_r(int fd, char* buffer, size_t size)
{
if (!validate_write(buffer, size))
return -EFAULT;
auto* descriptor = file_descriptor(fd);
if (!descriptor)
return -EBADF;
auto* master_pty = descriptor->master_pty();
if (!master_pty)
return -ENOTTY;
auto pts_name = master_pty->pts_name();
if (size < pts_name.length() + 1)
return -ERANGE;
strcpy(buffer, pts_name.characters());
return 0;
}
ssize_t Process::sys$write(int fd, const void* data, size_t size)
{
if (!validate_read(data, size))
@ -1270,7 +1288,7 @@ int Process::sys$open(const char* path, int options)
return -EFAULT;
if (number_of_open_file_descriptors() >= m_max_open_file_descriptors)
return -EMFILE;
int error;
int error = -EWHYTHO;
auto descriptor = VFS::the().open(path, error, options, cwd_inode()->identifier());
if (!descriptor)
return error;