Skip to content

Commit

Permalink
Make child process group foreground on active tty
Browse files Browse the repository at this point in the history
When a tty is available, make the child process group foreground on
(and graciously fallback if no tty is available).

Fix #19
  • Loading branch information
krallin committed Oct 28, 2015
1 parent e645af7 commit 85f3e87
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/tini.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 85f3e87

Please sign in to comment.