summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-09-30 14:05:28 +0330
committerAndreas Kling <kling@serenityos.org>2020-10-01 21:20:14 +0200
commita7828434c0bfb80ece6ce9a712e0d1a023a4a7e8 (patch)
tree58f26b54eaceda3ddaf3a0c6353535c67f685be1
parent422cb50e4ee5fac51223e4c8b69cb64f19f3178b (diff)
downloadserenity-a7828434c0bfb80ece6ce9a712e0d1a023a4a7e8.zip
Shell: Sneak a way into being a session leader
-rw-r--r--Shell/main.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/Shell/main.cpp b/Shell/main.cpp
index 98295bb480..46fc8200c8 100644
--- a/Shell/main.cpp
+++ b/Shell/main.cpp
@@ -133,11 +133,24 @@ int main(int argc, char** argv)
return 0;
}
- if (getsid(getpid()) == 0) {
+ auto pid = getpid();
+ if (auto sid = getsid(pid); sid == 0) {
if (setsid() < 0) {
perror("setsid");
// Let's just hope that it's ok.
}
+ } else if (sid != pid) {
+ if (getpgid(pid) != pid) {
+ dbgf("We were already in a session with sid={} (we are {}), let's do some gymnastics", sid, pid);
+ if (setpgid(pid, sid) < 0) {
+ auto strerr = strerror(errno);
+ dbgf("couldn't setpgid: {}", strerr);
+ }
+ if (setsid() < 0) {
+ auto strerr = strerror(errno);
+ dbgf("couldn't setsid: {}", strerr);
+ }
+ }
}
shell->current_script = argv[0];