summaryrefslogtreecommitdiff
path: root/Userland/sh.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-11-02 13:14:25 +0100
committerAndreas Kling <awesomekling@gmail.com>2018-11-02 13:14:25 +0100
commit621217ffeb9bddec866ad8895bd01973977f2848 (patch)
treea093956e51c52f13cc0f7003e278bc255f83acac /Userland/sh.cpp
parentd8f0dd6f3b36987c2a8021e16341dda16cbb7ab1 (diff)
downloadserenity-621217ffeb9bddec866ad8895bd01973977f2848.zip
Add tcsetpgrp()+tcgetpgrp().
One more step on the path to being able to ^C a runaway process. :^)
Diffstat (limited to 'Userland/sh.cpp')
-rw-r--r--Userland/sh.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Userland/sh.cpp b/Userland/sh.cpp
index 7ad8361153..c5669449c5 100644
--- a/Userland/sh.cpp
+++ b/Userland/sh.cpp
@@ -142,10 +142,17 @@ static int runcmd(char* cmd)
return 1;
}
+ // FIXME: This is racy, since spawn has already started the new process.
+ // Once I have fork()+exec(), pgrp setup can be done in the child before exec()ing.
+ tcsetpgrp(0, ret);
+
// FIXME: waitpid should give us the spawned process's exit status
int wstatus = 0;
waitpid(ret, &wstatus, 0);
+ // FIXME: Racy as mentioned above. Rework once we have fork()+exec().
+ tcsetpgrp(0, getpid());
+
if (WIFEXITED(wstatus)) {
//printf("Exited normally with status %d\n", WEXITSTATUS(wstatus));
} else {
@@ -173,6 +180,8 @@ int main(int, char**)
{
g = new GlobalState;
g->sid = setsid();
+ tcsetpgrp(0, getpgrp());
+
int rc = gethostname(g->hostname, sizeof(g->hostname));
if (rc < 0)
perror("gethostname");