Skip to content

Commit

Permalink
test: fix buggy getTTYfd() implementation
Browse files Browse the repository at this point in the history
PR-URL: #17781
Ref: #17781 (comment)
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
Trott authored and targos committed Mar 24, 2018
1 parent c6b993b commit 5f1a01d
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,25 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check
// Do our best to grab a tty fd.
function getTTYfd() {
const tty = require('tty');
let tty_fd = 0;
if (!tty.isatty(tty_fd)) tty_fd++;
else if (!tty.isatty(tty_fd)) tty_fd++;
else if (!tty.isatty(tty_fd)) tty_fd++;
else {
let ttyFd = [0, 1, 2].find(tty.isatty);
if (ttyFd === undefined) {
try {
tty_fd = fs.openSync('/dev/tty');
ttyFd = fs.openSync('/dev/tty');
} catch (e) {
// There aren't any tty fd's available to use.
return -1;
}
}
return tty_fd;
return ttyFd;
}

const tty_fd = getTTYfd();
if (tty_fd >= 0) {
const ttyFd = getTTYfd();
if (ttyFd >= 0) {
const tty_wrap = process.binding('tty_wrap');
// fd may still be invalid, so guard against it.
const handle = (() => {
try {
return new tty_wrap.TTY(tty_fd, false);
return new tty_wrap.TTY(ttyFd, false);
} catch (e) {
return null;
}
Expand Down

0 comments on commit 5f1a01d

Please sign in to comment.