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 BethGriggs committed Feb 6, 2020
1 parent 1d4e3d5 commit e00c4e4
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 @@ -97,6 +97,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 @@ -521,7 +524,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 e00c4e4

Please sign in to comment.