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.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Xu Meng authored and Beth Griggs committed 2020-02-06 02:49:07 +00:00
1 parent 1d4e3d50ab
commit e00c4e41b8
1 file changed
+10
+10
View File
@@ -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>
@@ -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