diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2019-07-04 12:11:00 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-07-06 20:44:29 +0200 |
commit | b06ce0bf8d6f50dd2666a3a0d117ccd58c76c694 (patch) | |
tree | 52be15ed35a6a12fbf644980664989bdb5ca77ab /src/node.cc | |
parent | 17862fca5f6acfad5941ec651769493310a5c571 (diff) | |
download | android-node-v8-b06ce0bf8d6f50dd2666a3a0d117ccd58c76c694.tar.gz android-node-v8-b06ce0bf8d6f50dd2666a3a0d117ccd58c76c694.tar.bz2 android-node-v8-b06ce0bf8d6f50dd2666a3a0d117ccd58c76c694.zip |
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: https://github.com/nodejs/node/issues/28530
Fixes: https://github.com/nodejs/node/issues/28479
Refs: https://github.com/nodejs/node/pull/28490
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src/node.cc')
-rw-r--r-- | src/node.cc | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/node.cc b/src/node.cc index 9fdef1a259..371e7c9f02 100644 --- a/src/node.cc +++ b/src/node.cc @@ -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__ |