Compare commits
No commits in common. "92ab403687c81e4304db41b42d93843ecd0e2e90" and "99dc819bca624f4cc6b489f86990729efd0cdb46" have entirely different histories.
92ab403687
...
99dc819bca
@ -99,7 +99,6 @@ Result<u64> SlavePTY::ioctl(int request, void* arg)
|
||||
});
|
||||
|
||||
m_master->m_session = current->sid;
|
||||
m_master->m_foreground_process_group = current->pgid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ set(SOURCES
|
||||
src/strtod.cpp
|
||||
src/math.cpp
|
||||
src/pty.cpp
|
||||
src/utmp.cpp
|
||||
src/sys/stat.cpp
|
||||
src/sys/mman.cpp
|
||||
src/sys/wait.cpp
|
||||
|
@ -14,9 +14,6 @@ extern "C"
|
||||
/* Find an available pseudoterminal pair and initialize it, returning file descriptors for both sides. */
|
||||
int openpty(int* master, int* slave, char* name, const struct termios* term, const struct winsize* win);
|
||||
|
||||
/* Create a new process operating in a pseudoterminal. */
|
||||
pid_t forkpty(int* master, char* name, const struct termios* term, const struct winsize* win);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,18 +0,0 @@
|
||||
/* utmp.h: Write entries to utmp files. */
|
||||
|
||||
#ifndef _UTMP_H
|
||||
#define _UTMP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Prepare a new terminal session on a tty. */
|
||||
int login_tty(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -5,7 +5,6 @@
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <utmp.h>
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
@ -45,27 +44,4 @@ extern "C"
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t forkpty(int* master, char* name, const struct termios* term, const struct winsize* win)
|
||||
{
|
||||
int slave;
|
||||
if (openpty(master, &slave, name, term, win) < 0) return -1;
|
||||
|
||||
pid_t child = fork();
|
||||
if (child < 0)
|
||||
{
|
||||
close(*master);
|
||||
close(slave);
|
||||
return -1;
|
||||
}
|
||||
if (!child)
|
||||
{
|
||||
close(*master);
|
||||
login_tty(slave);
|
||||
}
|
||||
else
|
||||
close(slave);
|
||||
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <utmp.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int login_tty(int fd)
|
||||
{
|
||||
setsid();
|
||||
|
||||
if (ioctl(fd, TIOCSCTTY) < 0) return -1;
|
||||
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -54,14 +54,34 @@ Result<void> TerminalWidget::init(char* const* args)
|
||||
signal(SIGCHLD, sigchld_handler);
|
||||
|
||||
int master;
|
||||
pid_t child = forkpty(&master, nullptr, nullptr, nullptr);
|
||||
if (child < 0) return err(errno);
|
||||
int slave;
|
||||
|
||||
int result = openpty(&master, &slave, nullptr, nullptr, nullptr);
|
||||
if (result < 0) return err(errno);
|
||||
|
||||
pid_t child = TRY(os::Process::fork());
|
||||
if (child == 0)
|
||||
{
|
||||
setsid();
|
||||
|
||||
close(master);
|
||||
|
||||
ioctl(slave, TIOCSCTTY);
|
||||
|
||||
dup2(slave, STDIN_FILENO);
|
||||
dup2(slave, STDOUT_FILENO);
|
||||
dup2(slave, STDERR_FILENO);
|
||||
|
||||
tcsetpgrp(slave, getpid());
|
||||
|
||||
close(slave);
|
||||
|
||||
execv(args[0], args);
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
close(slave);
|
||||
|
||||
m_pty = master;
|
||||
|
||||
fcntl(master, F_SETFL, O_NONBLOCK);
|
||||
|
Loading…
Reference in New Issue
Block a user