Skip to content

Commit

Permalink
src: block SIGTTOU before calling tcsetattr()
Browse files Browse the repository at this point in the history
We might be a background job that doesn't own the TTY so block SIGTTOU
before making the tcsetattr() call, otherwise that signal suspends us.

This is a better fix than PR #28490 for issue #28479.

Fixes: #28530
Fixes: #28479
Refs: #28490
  • Loading branch information
bnoordhuis committed Jul 4, 2019
1 parent 492037a commit 49acd1e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,20 @@ void ResetStdio() {
}

if (s.isatty) {
sigset_t sa;
int err;

// We might be a background job that doesn't own the TTY so block SIGTTOU
// before making the tcsetattr() call, otherwise that signal suspends us.
sigemptyset(&sa);
sigaddset(&sa, SIGTTOU);

CHECK_EQ(0, pthread_sigmask(SIG_BLOCK, &sa, nullptr));
do
err = tcsetattr(fd, TCSANOW, &s.termios);
while (err == -1 && errno == EINTR); // NOLINT
// EIO has been observed to be returned by the Linux kernel under some
// circumstances. Reading through drivers/tty/tty_io*.c, it seems to
// indicate the tty went away. Of course none of this is documented.
CHECK_IMPLIES(err == -1, errno == EIO);
CHECK_EQ(0, pthread_sigmask(SIG_UNBLOCK, &sa, nullptr));
CHECK_EQ(0, err);
}
}
#endif // __POSIX__
Expand Down

0 comments on commit 49acd1e

Please sign in to comment.