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 <riclau@uk.ibm.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
dmabupt authored and BridgeAR committed Dec 9, 2019
1 parent 6bdf8d1 commit 68874a6
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 68874a6

Please sign in to comment.