Skip to content

Commit

Permalink
src: fix the false isatty() issue on IBMi
Browse files Browse the repository at this point in the history
On IBMi PASE isatty() always returns true for stdin, stdout and stderr.
Use ioctl() instead to identify whether it's actually a TTY.

PR-URL: #30829
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
dmabupt authored and targos committed Dec 10, 2019
1 parent e551c16 commit 6088603
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
#include <unistd.h> // STDIN_FILENO, STDERR_FILENO
#endif

#ifdef __PASE__
#include <sys/ioctl.h> // ioctl
#endif
// ========== global C++ headers ==========

#include <cerrno>
Expand Down Expand Up @@ -555,7 +558,14 @@ inline void PlatformInit() {
while (s.flags == -1 && errno == EINTR); // NOLINT
CHECK_NE(s.flags, -1);

#ifdef __PASE__
// On IBMi PASE isatty() always returns true for stdin, stdout and stderr.
// Use ioctl() instead to identify whether it's actually a TTY.
if (ioctl(fd, TXISATTY + 0x81, nullptr) == -1 && errno == ENOTTY)
continue;
#else
if (!isatty(fd)) continue;
#endif
s.isatty = true;

do
Expand Down

0 comments on commit 6088603

Please sign in to comment.