From 26d6bf338e41c9c73eea4f854ff109e917378fa0 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 4 Oct 2024 17:23:31 +0300 Subject: [PATCH] Shell: Ignore SIGTTOU and set pgroup from parent instead of child This allows using the shell in linux! --- userspace/programs/Shell/main.cpp | 35 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/userspace/programs/Shell/main.cpp b/userspace/programs/Shell/main.cpp index ba2eaaeecf..355c43a4e3 100644 --- a/userspace/programs/Shell/main.cpp +++ b/userspace/programs/Shell/main.cpp @@ -4,11 +4,14 @@ #include #include +#include #include #include #include #include +#include #include +#include #include #define ERROR_RETURN(__msg, __ret) do { perror(__msg); return __ret; } while (false) @@ -483,24 +486,6 @@ pid_t execute_command_no_wait(BAN::Vector& args, int fd_in, int fd_ close(fd_out); } - if (pgrp == 0) - { - if(setpgid(0, 0) == -1) - { - perror("setpgid"); - exit(1); - } - if (isatty(0) && tcsetpgrp(0, getpgrp()) == -1) - { - perror("tcsetpgrp"); - exit(1); - } - } - else - { - setpgid(0, pgrp); - } - execv(executable_file.data(), cmd_args.data()); perror("execv"); exit(1); @@ -509,6 +494,18 @@ pid_t execute_command_no_wait(BAN::Vector& args, int fd_in, int fd_ if (pid == -1) ERROR_RETURN("fork", -1); + if (pgrp == 0 && isatty(0)) + { + if(setpgid(pid, pid) == -1) + perror("setpgid"); + if (tcsetpgrp(0, pid) == -1) + perror("tcsetpgrp"); + } + else + { + setpgid(pid, pgrp); + } + return pid; } @@ -791,6 +788,8 @@ int main(int argc, char** argv) if (signal(SIGINT, [](int) {}) == SIG_ERR) perror("signal"); + if (signal(SIGTTOU, SIG_IGN) == SIG_ERR) + perror("signal"); tcgetattr(0, &old_termios);