/* non-raw output; add CR to each NL */
G.tty_attrs.c_oflag = OPOST | ONLCR;
- G.tty_attrs.c_cc[VMIN] = 1; /* block reads if < 1 char is available */
- G.tty_attrs.c_cc[VTIME] = 0; /* no timeout (reads block forever) */
+ /* reads would block only if < 1 char is available */
+ G.tty_attrs.c_cc[VMIN] = 1;
+ /* no timeout (reads block forever) */
+ G.tty_attrs.c_cc[VTIME] = 0;
#ifdef __linux__
G.tty_attrs.c_line = 0;
#endif
* a session leader - which is quite possible for getty!
*/
pid = getpid();
- if (getsid(0) != pid)
+ if (getsid(0) != pid) {
+ //for debugging:
+ //bb_perror_msg_and_die("setsid failed:"
+ // " pid %d ppid %d"
+ // " sid %d pgid %d",
+ // pid, getppid(),
+ // getsid(0), getpgid(0));
bb_perror_msg_and_die("setsid");
+ }
/* Looks like we are already a session leader.
* In this case (setsid failed) we may still have ctty,
* and it may be different from tty we need to control!
*/
fd = open("/dev/tty", O_RDWR | O_NONBLOCK);
if (fd >= 0) {
+ /* TIOCNOTTY sends SIGHUP to the foreground
+ * process group - which may include us!
+ * Make sure to not die on it:
+ */
+ sighandler_t old = signal(SIGHUP, SIG_IGN);
ioctl(fd, TIOCNOTTY);
close(fd);
+ signal(SIGHUP, old);
}
}