Browse Source

Shell: Make a new session at start if there's no active session

AnotherTest 4 years ago
parent
commit
a43d9c4fe0
2 changed files with 11 additions and 2 deletions
  1. 4 2
      Shell/Shell.cpp
  2. 7 0
      Shell/main.cpp

+ 4 - 2
Shell/Shell.cpp

@@ -733,8 +733,10 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
             perror("setpgid");
             perror("setpgid");
 
 
         if (!m_is_subshell) {
         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)");
         }
         }
     }
     }
 
 

+ 7 - 0
Shell/main.cpp

@@ -209,6 +209,13 @@ int main(int argc, char** argv)
 
 
     parser.parse(argc, 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];
     shell->current_script = argv[0];
 
 
     if (!skip_rc_files) {
     if (!skip_rc_files) {