mirror of
https://github.com/RGBCube/serenity
synced 2025-07-06 05:17:36 +00:00
Shell: Sneak a way into being a session leader
This commit is contained in:
parent
422cb50e4e
commit
a7828434c0
1 changed files with 14 additions and 1 deletions
|
@ -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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue