Skip to content

Commit b06ce0b

Browse files
bnoordhuisaddaleax
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 17862fc commit b06ce0b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/node.cc

+10-4
Original file line numberDiff line numberDiff line change
@@ -688,14 +688,20 @@ void ResetStdio() {
688688
}
689689

690690
if (s.isatty) {
691+
sigset_t sa;
691692
int err;
693+
694+
// We might be a background job that doesn't own the TTY so block SIGTTOU
695+
// before making the tcsetattr() call, otherwise that signal suspends us.
696+
sigemptyset(&sa);
697+
sigaddset(&sa, SIGTTOU);
698+
699+
CHECK_EQ(0, pthread_sigmask(SIG_BLOCK, &sa, nullptr));
692700
do
693701
err = tcsetattr(fd, TCSANOW, &s.termios);
694702
while (err == -1 && errno == EINTR); // NOLINT
695-
// EIO has been observed to be returned by the Linux kernel under some
696-
// circumstances. Reading through drivers/tty/tty_io*.c, it seems to
697-
// indicate the tty went away. Of course none of this is documented.
698-
CHECK_IMPLIES(err == -1, errno == EIO);
703+
CHECK_EQ(0, pthread_sigmask(SIG_UNBLOCK, &sa, nullptr));
704+
CHECK_EQ(0, err);
699705
}
700706
}
701707
#endif // __POSIX__

0 commit comments

Comments
 (0)