Make child process group foreground on active tty

When a tty is available, make the child process group foreground on
(and graciously fallback if no tty is available).

Fix #19
This commit is contained in:
Thomas Orozco 2015-10-31 15:31:57 +01:00
parent 40d313000c
commit 82acbc5ccc
1 changed files with 11 additions and 0 deletions

View File

@ -83,6 +83,17 @@ int spawn(const sigset_t* const child_sigset_ptr, char* const argv[], int* const
// Parent
PRINT_INFO("Spawned child process '%s' with pid '%i'", argv[0], pid);
*child_pid_ptr = pid;
// If there is a tty, pass control over to the child process group
if (tcsetpgrp(STDIN_FILENO, pid)) {
if (errno == ENOTTY) {
PRINT_DEBUG("tcsetpgrp failed: no tty (ok to proceed)")
} else {
PRINT_FATAL("tcsetpgrp failed: '%s'", strerror(errno));
return 1;
}
}
return 0;
}
}