We rely on the assumption that if a syscall returns an error, errno will be nonzero. See http://llvm.org/bugs/show_bug.cgi?id=18701
Also grab fd's that are attached to /dev/console.
[firstname.lastname@example.org: Minor cleanup, remove $REPTYR_REDIRECT entirely]
REPTYR_PTY is set path to pty. If REPTYR_REDIRECT is set, stdin,stdout and stderr are automatically redirected for the program that is started.
Allows usage of reptry in scripts and other programs
If a process is run as $cmd 2>/dev/null, we can still find a terminal on fd's 0 and 1, so don't spuriously error out.
[email@example.com: Use sig_atomic_t, and document the remaining race better]
[firstname.lastname@example.org: Split out from a larger commit]
reptyr should just work and not utter all those debug messages unless asked. Signed-off-by: Randy MacLeod <email@example.com> [firstname.lastname@example.org: Reduce nesting in debug()] Signed-off-by: Nelson Elhage <email@example.com>
Reported-by: Michael Orlitzky <firstname.lastname@example.org>