Skip to content

Commit d4113f9

Browse files
bnoordhuistargos
authored andcommitted
src: block SIGTTOU before calling tcsetattr()
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 <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
1 parent 66382ab commit d4113f9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/node.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,20 @@ void ResetStdio() {
640640
}
641641

642642
if (s.isatty) {
643+
sigset_t sa;
643644
int err;
645+
646+
// We might be a background job that doesn't own the TTY so block SIGTTOU
647+
// before making the tcsetattr() call, otherwise that signal suspends us.
648+
sigemptyset(&sa);
649+
sigaddset(&sa, SIGTTOU);
650+
651+
CHECK_EQ(0, pthread_sigmask(SIG_BLOCK, &sa, nullptr));
644652
do
645653
err = tcsetattr(fd, TCSANOW, &s.termios);
646654
while (err == -1 && errno == EINTR); // NOLINT
647-
// EIO has been observed to be returned by the Linux kernel under some
648-
// circumstances. Reading through drivers/tty/tty_io*.c, it seems to
649-
// indicate the tty went away. Of course none of this is documented.
650-
CHECK_IMPLIES(err == -1, errno == EIO);
655+
CHECK_EQ(0, pthread_sigmask(SIG_UNBLOCK, &sa, nullptr));
656+
CHECK_EQ(0, err);
651657
}
652658
}
653659
#endif // __POSIX__

0 commit comments

Comments
 (0)