From 5644ec613134082fec8bdad63098e7340fa3a8be Mon Sep 17 00:00:00 2001 From: Xu Meng Date: Fri, 6 Dec 2019 20:54:00 -0600 Subject: [PATCH] src: fix the false isatty() issue on IBMi On IBMi PASE isatty() always returns true for stdin, stdout and stderr. Use ioctl() instead to identify whether it's actually a TTY. --- src/node.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/node.cc b/src/node.cc index 91f07e447f0a6f..b44f021084262e 100644 --- a/src/node.cc +++ b/src/node.cc @@ -108,6 +108,9 @@ #include // STDIN_FILENO, STDERR_FILENO #endif +#ifdef __PASE__ +#include // ioctl +#endif // ========== global C++ headers ========== #include @@ -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