1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:57:44 +00:00

Add tcsetpgrp()+tcgetpgrp().

One more step on the path to being able to ^C a runaway process. :^)
This commit is contained in:
Andreas Kling 2018-11-02 13:14:25 +01:00
parent d8f0dd6f3b
commit 621217ffeb
11 changed files with 72 additions and 4 deletions

View file

@ -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");