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

PR-URL: #28535
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
  • Loading branch information
bnoordhuis authored and targos committed Jul 20, 2019
1 parent 66382ab commit d4113f9
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 @@ -640,14 +640,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 d4113f9

Please sign in to comment.