Compare commits
2 Commits
5f0830cd41
...
c323a812a5
Author | SHA1 | Date | |
---|---|---|---|
c323a812a5 | |||
81131ad3a8 |
102
apps/init.cpp
102
apps/init.cpp
@ -365,6 +365,40 @@ static void mount_devpts()
|
|||||||
if (mount("/dev/pts", "devpts", "devpts") < 0) exit(255);
|
if (mount("/dev/pts", "devpts", "devpts") < 0) exit(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void wait_for_child(int)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
auto rc = os::Process::wait(os::Process::ANY_CHILD, &status);
|
||||||
|
if (rc.has_error())
|
||||||
|
{
|
||||||
|
do_log("[init] waitpid error %s", rc.error_string());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t child = rc.release_value();
|
||||||
|
|
||||||
|
for (auto& service : g_services)
|
||||||
|
{
|
||||||
|
if (service.pid.has_value() && service.pid.value() == child)
|
||||||
|
{
|
||||||
|
if (WIFEXITED(status))
|
||||||
|
{
|
||||||
|
do_log("[init] service %s exited with status %d\n", service.name.chars(), WEXITSTATUS(status));
|
||||||
|
}
|
||||||
|
else { do_log("[init] service %s was terminated by signal %d\n", service.name.chars(), WTERMSIG(status)); }
|
||||||
|
|
||||||
|
if (service.restart)
|
||||||
|
{
|
||||||
|
do_log("[init] restarting service %s\n", service.name.chars());
|
||||||
|
|
||||||
|
start_service(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Result<int> sysinit(StringView path)
|
Result<int> sysinit(StringView path)
|
||||||
{
|
{
|
||||||
if (getpid() != 1)
|
if (getpid() != 1)
|
||||||
@ -404,38 +438,7 @@ Result<int> sysinit(StringView path)
|
|||||||
if (path.is_empty()) path = "/etc/init";
|
if (path.is_empty()) path = "/etc/init";
|
||||||
start_services(path);
|
start_services(path);
|
||||||
|
|
||||||
while (1)
|
while (1) { wait_for_child(0); }
|
||||||
{
|
|
||||||
int status;
|
|
||||||
auto rc = os::Process::wait(os::Process::ANY_CHILD, &status);
|
|
||||||
if (rc.has_error()) continue;
|
|
||||||
|
|
||||||
pid_t child = rc.release_value();
|
|
||||||
|
|
||||||
for (auto& service : g_services)
|
|
||||||
{
|
|
||||||
if (service.pid.has_value() && service.pid.value() == child)
|
|
||||||
{
|
|
||||||
if (WIFEXITED(status))
|
|
||||||
{
|
|
||||||
do_log("[init] service %s exited with status %d\n", service.name.chars(), WEXITSTATUS(status));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
do_log("[init] service %s was terminated by signal %d\n", service.name.chars(), WTERMSIG(status));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (service.restart)
|
|
||||||
{
|
|
||||||
do_log("[init] restarting service %s\n", service.name.chars());
|
|
||||||
|
|
||||||
start_service(service);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<int> user_init(StringView path)
|
Result<int> user_init(StringView path)
|
||||||
@ -454,38 +457,7 @@ Result<int> user_init(StringView path)
|
|||||||
|
|
||||||
TRY(os::Security::pledge("stdio rpath wpath proc exec", nullptr));
|
TRY(os::Security::pledge("stdio rpath wpath proc exec", nullptr));
|
||||||
|
|
||||||
while (1)
|
while (1) { wait_for_child(0); }
|
||||||
{
|
|
||||||
int status;
|
|
||||||
auto rc = os::Process::wait(os::Process::ANY_CHILD, &status);
|
|
||||||
if (rc.has_error()) continue;
|
|
||||||
|
|
||||||
pid_t child = rc.release_value();
|
|
||||||
|
|
||||||
for (auto& service : g_services)
|
|
||||||
{
|
|
||||||
if (service.pid.has_value() && service.pid.value() == child)
|
|
||||||
{
|
|
||||||
if (WIFEXITED(status))
|
|
||||||
{
|
|
||||||
do_log("[init] service %s exited with status %d\n", service.name.chars(), WEXITSTATUS(status));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
do_log("[init] service %s was terminated by signal %d\n", service.name.chars(), WTERMSIG(status));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (service.restart)
|
|
||||||
{
|
|
||||||
do_log("[init] restarting service %s\n", service.name.chars());
|
|
||||||
|
|
||||||
start_service(service);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<int> luna_main(int argc, char** argv)
|
Result<int> luna_main(int argc, char** argv)
|
||||||
@ -501,6 +473,8 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
"change the default service path (/etc/init or /etc/user)");
|
"change the default service path (/etc/init or /etc/user)");
|
||||||
parser.parse(argc, argv);
|
parser.parse(argc, argv);
|
||||||
|
|
||||||
|
signal(SIGCHLD, wait_for_child);
|
||||||
|
|
||||||
if (user) return user_init(service_path);
|
if (user) return user_init(service_path);
|
||||||
return sysinit(service_path);
|
return sysinit(service_path);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
||||||
_e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill) _e(sigprocmask) _e(setpgid) _e(isatty) \
|
_e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill) _e(sigprocmask) _e(setpgid) _e(isatty) \
|
||||||
_e(getpgid) _e(socket) _e(bind) _e(connect) _e(listen) _e(accept) _e(poll) _e(msync) \
|
_e(getpgid) _e(socket) _e(bind) _e(connect) _e(listen) _e(accept) _e(poll) _e(msync) \
|
||||||
_e(truncate) _e(ftruncate) _e(utimensat) _e(alarm) _e(pledge) _e(memstat)
|
_e(truncate) _e(ftruncate) _e(utimensat) _e(alarm) _e(pledge) _e(memstat) _e(setsid) \
|
||||||
|
_e(getsid)
|
||||||
|
|
||||||
enum Syscalls
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
@ -203,37 +203,6 @@ Result<u64> MasterPTY::ioctl(int request, void* arg)
|
|||||||
|
|
||||||
switch (request)
|
switch (request)
|
||||||
{
|
{
|
||||||
case TCGETS: {
|
|
||||||
return MemoryManager::copy_to_user_typed((struct termios*)arg, &m_settings) ? 0 : err(EFAULT);
|
|
||||||
}
|
|
||||||
case TCSETS: {
|
|
||||||
if (!MemoryManager::copy_from_user_typed((const struct termios*)arg, &m_settings)) return err(EFAULT);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case TIOCSPGRP: {
|
|
||||||
pid_t pgid;
|
|
||||||
if (!MemoryManager::copy_from_user_typed((const pid_t*)arg, &pgid)) return err(EFAULT);
|
|
||||||
|
|
||||||
bool pgid_exists = false;
|
|
||||||
Scheduler::for_each_in_process_group(pgid, [&pgid_exists](Thread*) {
|
|
||||||
pgid_exists = true;
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
if (!pgid_exists) return err(EPERM);
|
|
||||||
|
|
||||||
m_foreground_process_group = pgid;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case TIOCGPGRP: {
|
|
||||||
pid_t pgid = m_foreground_process_group.value_or((pid_t)next_thread_id());
|
|
||||||
if (!MemoryManager::copy_to_user_typed((pid_t*)arg, &pgid)) return err(EFAULT);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case TIOCGWINSZ: {
|
|
||||||
if (!MemoryManager::copy_to_user_typed((struct winsize*)arg, &m_window)) return err(EFAULT);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case TIOCGPTN: {
|
case TIOCGPTN: {
|
||||||
if (!MemoryManager::copy_to_user_typed((int*)arg, &m_index)) return err(EFAULT);
|
if (!MemoryManager::copy_to_user_typed((int*)arg, &m_index)) return err(EFAULT);
|
||||||
return 0;
|
return 0;
|
||||||
@ -247,4 +216,10 @@ MasterPTY::~MasterPTY()
|
|||||||
m_slave->m_master = nullptr;
|
m_slave->m_master = nullptr;
|
||||||
for (auto& fs : g_devpts_instances) { fs->root_inode()->remove_entry(m_slave->m_name.chars()); }
|
for (auto& fs : g_devpts_instances) { fs->root_inode()->remove_entry(m_slave->m_name.chars()); }
|
||||||
PTYMultiplexer::did_remove_pty(m_index);
|
PTYMultiplexer::did_remove_pty(m_index);
|
||||||
|
|
||||||
|
if (m_session.has_value())
|
||||||
|
{
|
||||||
|
auto leader = Scheduler::find_by_pid(*m_session);
|
||||||
|
if (leader.has_value()) leader.value()->send_signal(SIGHUP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ class MasterPTY : public VFS::DeviceInode
|
|||||||
mutable Buffer m_buffer;
|
mutable Buffer m_buffer;
|
||||||
SharedPtr<SlavePTY> m_slave;
|
SharedPtr<SlavePTY> m_slave;
|
||||||
mutable Option<pid_t> m_foreground_process_group;
|
mutable Option<pid_t> m_foreground_process_group;
|
||||||
|
mutable Option<pid_t> m_session;
|
||||||
struct winsize m_window;
|
struct winsize m_window;
|
||||||
|
|
||||||
typedef Vector<u8> Line;
|
typedef Vector<u8> Line;
|
||||||
|
@ -63,18 +63,23 @@ Result<u64> SlavePTY::ioctl(int request, void* arg)
|
|||||||
case TIOCSPGRP: {
|
case TIOCSPGRP: {
|
||||||
pid_t pgid;
|
pid_t pgid;
|
||||||
if (!MemoryManager::copy_from_user_typed((const pid_t*)arg, &pgid)) return err(EFAULT);
|
if (!MemoryManager::copy_from_user_typed((const pid_t*)arg, &pgid)) return err(EFAULT);
|
||||||
|
if (current->controlling_terminal != SharedPtr<VFS::Inode> { this }) return err(ENOTTY);
|
||||||
|
|
||||||
bool pgid_exists = false;
|
bool pgid_exists = false;
|
||||||
Scheduler::for_each_in_process_group(pgid, [&pgid_exists](Thread*) {
|
pid_t sid;
|
||||||
|
Scheduler::for_each_in_process_group(pgid, [&pgid_exists, &sid](Thread* thread) {
|
||||||
pgid_exists = true;
|
pgid_exists = true;
|
||||||
|
sid = thread->sid; // should be the same for all threads in the process group
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
if (!pgid_exists) return err(EPERM);
|
if (!pgid_exists) return err(EPERM);
|
||||||
|
if (sid != current->sid) return err(EPERM);
|
||||||
|
|
||||||
m_master->m_foreground_process_group = pgid;
|
m_master->m_foreground_process_group = pgid;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case TIOCGPGRP: {
|
case TIOCGPGRP: {
|
||||||
|
if (current->controlling_terminal != SharedPtr<VFS::Inode> { this }) return err(ENOTTY);
|
||||||
pid_t pgid = m_master->m_foreground_process_group.value_or((pid_t)next_thread_id());
|
pid_t pgid = m_master->m_foreground_process_group.value_or((pid_t)next_thread_id());
|
||||||
if (!MemoryManager::copy_to_user_typed((pid_t*)arg, &pgid)) return err(EFAULT);
|
if (!MemoryManager::copy_to_user_typed((pid_t*)arg, &pgid)) return err(EFAULT);
|
||||||
return 0;
|
return 0;
|
||||||
@ -83,6 +88,20 @@ Result<u64> SlavePTY::ioctl(int request, void* arg)
|
|||||||
if (!MemoryManager::copy_to_user_typed((struct winsize*)arg, &m_master->m_window)) return err(EFAULT);
|
if (!MemoryManager::copy_to_user_typed((struct winsize*)arg, &m_master->m_window)) return err(EFAULT);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
case TIOCSCTTY: {
|
||||||
|
if (current->controlling_terminal) return err(EPERM);
|
||||||
|
if (this->m_master->m_session.has_value()) return err(EPERM);
|
||||||
|
if (!current->is_session_leader()) return err(EPERM);
|
||||||
|
|
||||||
|
Scheduler::for_each_in_session(current->sid, [this](Thread* thread) {
|
||||||
|
thread->controlling_terminal = this;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
m_master->m_session = current->sid;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
default: return err(EINVAL);
|
default: return err(EINVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,9 @@ Result<u64> sys_fork(Registers* regs, SyscallArgs)
|
|||||||
thread->parent = current;
|
thread->parent = current;
|
||||||
thread->promises = current->promises;
|
thread->promises = current->promises;
|
||||||
thread->execpromises = current->execpromises;
|
thread->execpromises = current->execpromises;
|
||||||
|
thread->controlling_terminal = current->controlling_terminal;
|
||||||
|
thread->pgid = current->pgid;
|
||||||
|
thread->sid = current->sid;
|
||||||
|
|
||||||
for (int i = 0; i < FD_MAX; i++) { thread->fd_table[i] = current->fd_table[i]; }
|
for (int i = 0; i < FD_MAX; i++) { thread->fd_table[i] = current->fd_table[i]; }
|
||||||
|
|
||||||
|
@ -130,18 +130,21 @@ Result<u64> sys_setpgid(Registers*, SyscallArgs args)
|
|||||||
auto* thread = TRY(Result<Thread*>::from_option(Scheduler::find_by_pid(pid), ESRCH));
|
auto* thread = TRY(Result<Thread*>::from_option(Scheduler::find_by_pid(pid), ESRCH));
|
||||||
if (thread != current && thread->parent != current) return err(ESRCH);
|
if (thread != current && thread->parent != current) return err(ESRCH);
|
||||||
|
|
||||||
// FIXME: Weird session stuff, we don't have that currently.
|
if (thread->is_session_leader() || thread->sid != current->sid) return err(EPERM);
|
||||||
|
|
||||||
if (thread->has_called_exec) return err(EPERM);
|
if (thread->has_called_exec) return err(EPERM);
|
||||||
|
|
||||||
if (pgid != current->id)
|
if (pgid != current->id)
|
||||||
{
|
{
|
||||||
bool pgid_exists = false;
|
bool pgid_exists = false;
|
||||||
Scheduler::for_each_in_process_group(pgid, [&pgid_exists](Thread*) {
|
pid_t sid;
|
||||||
|
Scheduler::for_each_in_process_group(pgid, [&pgid_exists, &sid](Thread* t) {
|
||||||
pgid_exists = true;
|
pgid_exists = true;
|
||||||
|
sid = t->sid; // this should be the same for all threads in the process group
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
if (!pgid_exists) return err(EPERM);
|
if (!pgid_exists) return err(EPERM);
|
||||||
|
if (sid != thread->sid) return err(EPERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
thread->pgid = (u64)pgid;
|
thread->pgid = (u64)pgid;
|
||||||
@ -164,6 +167,33 @@ Result<u64> sys_getpgid(Registers*, SyscallArgs args)
|
|||||||
return (u64)thread->pgid;
|
return (u64)thread->pgid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<u64> sys_setsid(Registers*, SyscallArgs)
|
||||||
|
{
|
||||||
|
auto* current = Scheduler::current();
|
||||||
|
TRY(check_pledge(current, Promise::p_proc));
|
||||||
|
|
||||||
|
if (current->pgid == current->id) return err(EPERM);
|
||||||
|
|
||||||
|
current->sid = current->pgid = current->id;
|
||||||
|
current->controlling_terminal = {};
|
||||||
|
|
||||||
|
return current->sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<u64> sys_getsid(Registers*, SyscallArgs args)
|
||||||
|
{
|
||||||
|
pid_t pid = (pid_t)args[0];
|
||||||
|
|
||||||
|
auto* current = Scheduler::current();
|
||||||
|
TRY(check_pledge(current, Promise::p_stdio));
|
||||||
|
|
||||||
|
if (pid == 0) pid = current->id;
|
||||||
|
|
||||||
|
auto* thread = TRY(Result<Thread*>::from_option(Scheduler::find_by_pid(pid), ESRCH));
|
||||||
|
|
||||||
|
return thread->sid;
|
||||||
|
}
|
||||||
|
|
||||||
Result<u64> sys_fchmodat(Registers*, SyscallArgs args)
|
Result<u64> sys_fchmodat(Registers*, SyscallArgs args)
|
||||||
{
|
{
|
||||||
int dirfd = (int)args[0];
|
int dirfd = (int)args[0];
|
||||||
|
@ -61,6 +61,19 @@ namespace Scheduler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Callback> void for_each_in_session(pid_t sid, Callback callback)
|
||||||
|
{
|
||||||
|
for (Thread* current = g_threads.first().value_or(nullptr); current;
|
||||||
|
current = g_threads.next(current).value_or(nullptr))
|
||||||
|
{
|
||||||
|
if (current->sid == sid)
|
||||||
|
{
|
||||||
|
bool should_continue = callback(current);
|
||||||
|
if (!should_continue) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void dump_state();
|
void dump_state();
|
||||||
|
|
||||||
bool has_children(Thread* thread);
|
bool has_children(Thread* thread);
|
||||||
|
@ -93,6 +93,20 @@ Result<SharedPtr<VFS::Inode>> Thread::resolve_atfile(int dirfd, const String& pa
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (is_session_leader())
|
||||||
|
{
|
||||||
|
kinfoln("thread %d is exiting as a session leader, sending signals to session", id);
|
||||||
|
// FIXME: Send SIGHUP only to the foreground process group if the session has a controlling terminal.
|
||||||
|
Scheduler::for_each_in_session(sid, [this](Thread* thread) {
|
||||||
|
if (thread == this) return true;
|
||||||
|
thread->sid = 0;
|
||||||
|
thread->controlling_terminal = {};
|
||||||
|
thread->send_signal(SIGHUP);
|
||||||
|
kinfoln("reparenting and sending SIGHUP to %d", thread->id);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (parent)
|
if (parent)
|
||||||
{
|
{
|
||||||
if (parent->state == ThreadState::Waiting)
|
if (parent->state == ThreadState::Waiting)
|
||||||
@ -104,7 +118,11 @@ Result<SharedPtr<VFS::Inode>> Thread::resolve_atfile(int dirfd, const String& pa
|
|||||||
parent->wake_up();
|
parent->wake_up();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { parent->send_signal(SIGCHLD); }
|
else
|
||||||
|
{
|
||||||
|
while (parent->pending_signals.get(SIGCHLD - 1)) kernel_yield();
|
||||||
|
parent->send_signal(SIGCHLD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state = ThreadState::Exited;
|
state = ThreadState::Exited;
|
||||||
|
@ -78,6 +78,7 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
|
|
||||||
pid_t id;
|
pid_t id;
|
||||||
pid_t pgid { 0 };
|
pid_t pgid { 0 };
|
||||||
|
pid_t sid { 0 };
|
||||||
|
|
||||||
Credentials auth;
|
Credentials auth;
|
||||||
|
|
||||||
@ -152,6 +153,11 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
state = ThreadState::Runnable;
|
state = ThreadState::Runnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_session_leader()
|
||||||
|
{
|
||||||
|
return id == sid;
|
||||||
|
}
|
||||||
|
|
||||||
void init_regs_kernel();
|
void init_regs_kernel();
|
||||||
void init_regs_user();
|
void init_regs_user();
|
||||||
|
|
||||||
|
@ -46,5 +46,6 @@ struct winsize
|
|||||||
#define TIOCGPGRP 3
|
#define TIOCGPGRP 3
|
||||||
#define TIOCGWINSZ 4
|
#define TIOCGWINSZ 4
|
||||||
#define TIOCGPTN 5
|
#define TIOCGPTN 5
|
||||||
|
#define TIOCSCTTY 6
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,6 +52,9 @@ extern "C"
|
|||||||
/* Return a process' process group ID. */
|
/* Return a process' process group ID. */
|
||||||
pid_t getpgid(pid_t pid);
|
pid_t getpgid(pid_t pid);
|
||||||
|
|
||||||
|
/* Return a process' session ID. */
|
||||||
|
pid_t getsid(pid_t pid);
|
||||||
|
|
||||||
/* Set the current process' user IDs. */
|
/* Set the current process' user IDs. */
|
||||||
int setuid(uid_t uid);
|
int setuid(uid_t uid);
|
||||||
|
|
||||||
@ -67,6 +70,9 @@ extern "C"
|
|||||||
/* Set the current process or a child process's process group. */
|
/* Set the current process or a child process's process group. */
|
||||||
int setpgid(pid_t pid, pid_t pgid);
|
int setpgid(pid_t pid, pid_t pgid);
|
||||||
|
|
||||||
|
/* Create a new session and make this process the leader of it. */
|
||||||
|
pid_t setsid(void);
|
||||||
|
|
||||||
/* Change the owner and group of a file. */
|
/* Change the owner and group of a file. */
|
||||||
int chown(const char* path, uid_t uid, gid_t gid);
|
int chown(const char* path, uid_t uid, gid_t gid);
|
||||||
|
|
||||||
|
@ -527,4 +527,16 @@ extern "C"
|
|||||||
long rc = syscall(SYS_pledge, promises, execpromises);
|
long rc = syscall(SYS_pledge, promises, execpromises);
|
||||||
__errno_return(rc, int);
|
__errno_return(rc, int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t getsid(pid_t pid)
|
||||||
|
{
|
||||||
|
long rc = syscall(SYS_getsid, pid);
|
||||||
|
__errno_return(rc, pid_t);
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t setsid()
|
||||||
|
{
|
||||||
|
long rc = syscall(SYS_setsid);
|
||||||
|
__errno_return(rc, pid_t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <pty.h>
|
#include <pty.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ui/App.h>
|
#include <ui/App.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -61,13 +62,16 @@ Result<void> TerminalWidget::init(char* const* args)
|
|||||||
pid_t child = TRY(os::Process::fork());
|
pid_t child = TRY(os::Process::fork());
|
||||||
if (child == 0)
|
if (child == 0)
|
||||||
{
|
{
|
||||||
|
setsid();
|
||||||
|
|
||||||
close(master);
|
close(master);
|
||||||
|
|
||||||
|
ioctl(slave, TIOCSCTTY);
|
||||||
|
|
||||||
dup2(slave, STDIN_FILENO);
|
dup2(slave, STDIN_FILENO);
|
||||||
dup2(slave, STDOUT_FILENO);
|
dup2(slave, STDOUT_FILENO);
|
||||||
dup2(slave, STDERR_FILENO);
|
dup2(slave, STDERR_FILENO);
|
||||||
|
|
||||||
setpgid(0, 0);
|
|
||||||
tcsetpgrp(slave, getpid());
|
tcsetpgrp(slave, getpid());
|
||||||
|
|
||||||
close(slave);
|
close(slave);
|
||||||
|
@ -88,8 +88,6 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
|
|
||||||
Mouse mouse_pointer { screen.canvas() };
|
Mouse mouse_pointer { screen.canvas() };
|
||||||
|
|
||||||
setpgid(0, 0);
|
|
||||||
|
|
||||||
int fd = open("/dev/null", O_RDONLY);
|
int fd = open("/dev/null", O_RDONLY);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
@ -109,6 +107,8 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setsid() < 0) perror("setsid");
|
||||||
|
|
||||||
auto server = TRY(os::LocalServer::create(socket_path, false));
|
auto server = TRY(os::LocalServer::create(socket_path, false));
|
||||||
TRY(server->listen(20));
|
TRY(server->listen(20));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user