From a43d9c4fe065a655579d4c06f6de5b2e5eecbb9f Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Fri, 18 Sep 2020 11:22:25 +0430 Subject: [PATCH] Shell: Make a new session at start if there's no active session --- Shell/Shell.cpp | 6 ++++-- Shell/main.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index 296630b507c..adec2a70015 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -733,8 +733,10 @@ RefPtr Shell::run_command(const AST::Command& command) perror("setpgid"); if (!m_is_subshell) { - tcsetpgrp(STDOUT_FILENO, pgid); - tcsetpgrp(STDIN_FILENO, pgid); + if (tcsetpgrp(STDOUT_FILENO, pgid) != 0) + perror("tcsetpgrp(OUT)"); + if (tcsetpgrp(STDIN_FILENO, pgid) != 0) + perror("tcsetpgrp(IN)"); } } diff --git a/Shell/main.cpp b/Shell/main.cpp index 59610866804..ff266349139 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -209,6 +209,13 @@ int main(int argc, char** argv) parser.parse(argc, argv); + if (getsid(getpid()) == 0) { + if (setsid() < 0) { + perror("setsid"); + // Let's just hope that it's ok. + } + } + shell->current_script = argv[0]; if (!skip_rc_files) {