summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Lucas <evanlucas@me.com>2018-06-11 09:20:50 -0500
committerAnna Henningsen <anna@addaleax.net>2018-06-12 00:16:13 +0200
commit14dc17df38d81bed0ab675fdcc58c9a574bd6401 (patch)
tree9ab168892de7e9a705fa9854a3190c4bc8dc184f
parent43fd1d793af09aea3789f0e2af88d7f189d696a1 (diff)
downloadandroid-node-v8-14dc17df38d81bed0ab675fdcc58c9a574bd6401.tar.gz
android-node-v8-14dc17df38d81bed0ab675fdcc58c9a574bd6401.tar.bz2
android-node-v8-14dc17df38d81bed0ab675fdcc58c9a574bd6401.zip
Revert "src: restore stdio on program exit"
This reverts commit c2c9c0c3d3199453cb74f64432fb76237d6f4ec4. It seems to be causing hangs when piping output to other processes. PR-URL: https://github.com/nodejs/node/pull/21257 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
-rw-r--r--src/node.cc100
1 files changed, 6 insertions, 94 deletions
diff --git a/src/node.cc b/src/node.cc
index bdeb2b1317..7cc9131f98 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -100,7 +100,6 @@ typedef int mode_t;
#else
#include <pthread.h>
#include <sys/resource.h> // getrlimit, setrlimit
-#include <termios.h> // tcgetattr, tcsetattr
#include <unistd.h> // setuid, getuid
#endif
@@ -173,9 +172,6 @@ using v8::Value;
static Mutex process_mutex;
static Mutex environ_mutex;
-// Safe to call more than once and from signal handlers.
-inline void PlatformExit();
-
static bool print_eval = false;
static bool force_repl = false;
static bool syntax_check_only = false;
@@ -886,7 +882,7 @@ void AppendExceptionLine(Environment* env,
Mutex::ScopedLock lock(process_mutex);
env->set_printed_error(true);
- PlatformExit();
+ uv_tty_reset_mode();
PrintErrorString("\n%s", arrow);
return;
}
@@ -2797,7 +2793,7 @@ void SetupProcessObject(Environment* env,
void SignalExit(int signo) {
- PlatformExit();
+ uv_tty_reset_mode();
v8_platform.StopTracingAgent();
#ifdef __FreeBSD__
// FreeBSD has a nasty bug, see RegisterSignalHandler for details
@@ -3629,27 +3625,6 @@ static void DebugEnd(const FunctionCallbackInfo<Value>& args) {
}
-#ifdef __POSIX__
-static struct {
- int flags;
- bool isatty;
- struct stat stat;
- struct termios termios;
-} stdio[1 + STDERR_FILENO];
-
-
-inline int GetFileDescriptorFlags(int fd) {
- int flags;
-
- do {
- flags = fcntl(fd, F_GETFL);
- } while (flags == -1 && errno == EINTR);
-
- return flags;
-}
-#endif // __POSIX__
-
-
inline void PlatformInit() {
#ifdef __POSIX__
#if HAVE_INSPECTOR
@@ -3660,9 +3635,9 @@ inline void PlatformInit() {
#endif // HAVE_INSPECTOR
// Make sure file descriptors 0-2 are valid before we start logging anything.
- for (auto& s : stdio) {
- const int fd = &s - stdio;
- if (fstat(fd, &s.stat) == 0)
+ for (int fd = STDIN_FILENO; fd <= STDERR_FILENO; fd += 1) {
+ struct stat ignored;
+ if (fstat(fd, &ignored) == 0)
continue;
// Anything but EBADF means something is seriously wrong. We don't
// have to special-case EINTR, fstat() is not interruptible.
@@ -3670,8 +3645,6 @@ inline void PlatformInit() {
ABORT();
if (fd != open("/dev/null", O_RDWR))
ABORT();
- if (fstat(fd, &s.stat) != 0)
- ABORT();
}
#if HAVE_INSPECTOR
@@ -3694,24 +3667,6 @@ inline void PlatformInit() {
}
#endif // !NODE_SHARED_MODE
- // Record the state of the stdio file descriptors so we can restore it
- // on exit. Needs to happen before installing signal handlers because
- // they make use of that information.
- for (auto& s : stdio) {
- const int fd = &s - stdio;
- int err;
-
- s.flags = GetFileDescriptorFlags(fd);
- CHECK_NE(s.flags, -1);
-
- if (!isatty(fd)) continue;
- s.isatty = true;
- do {
- err = tcgetattr(fd, &s.termios);
- } while (err == -1 && errno == EINTR);
- CHECK_EQ(err, 0);
- }
-
RegisterSignalHandler(SIGINT, SignalExit, true);
RegisterSignalHandler(SIGTERM, SignalExit, true);
@@ -3752,49 +3707,6 @@ inline void PlatformInit() {
}
-// This function must be safe to call more than once and from signal handlers.
-inline void PlatformExit() {
-#ifdef __POSIX__
- for (auto& s : stdio) {
- const int fd = &s - stdio;
-
- struct stat tmp;
- if (-1 == fstat(fd, &tmp)) {
- CHECK_EQ(errno, EBADF); // Program closed file descriptor.
- continue;
- }
-
- bool is_same_file =
- (s.stat.st_dev == tmp.st_dev && s.stat.st_ino == tmp.st_ino);
- if (!is_same_file) continue; // Program reopened file descriptor.
-
- int flags = GetFileDescriptorFlags(fd);
- CHECK_NE(flags, -1);
-
- // Restore the O_NONBLOCK flag if it changed.
- if (O_NONBLOCK & (flags ^ s.flags)) {
- flags &= ~O_NONBLOCK;
- flags |= s.flags & O_NONBLOCK;
-
- int err;
- do {
- err = fcntl(fd, F_SETFL, flags);
- } while (err == -1 && errno == EINTR);
- CHECK_NE(err, -1);
- }
-
- if (s.isatty) {
- int err;
- do {
- err = tcsetattr(fd, TCSANOW, &s.termios);
- } while (err == -1 && errno == EINTR);
- CHECK_NE(err, -1);
- }
- }
-#endif // __POSIX__
-}
-
-
void ProcessArgv(int* argc,
const char** argv,
int* exec_argc,
@@ -4266,7 +4178,7 @@ inline int Start(uv_loop_t* event_loop,
}
int Start(int argc, char** argv) {
- atexit([] () { PlatformExit(); });
+ atexit([] () { uv_tty_reset_mode(); });
PlatformInit();
performance::performance_node_start = PERFORMANCE_NOW();