Skip to content

Commit 57a47b1

Browse files
committed
Reverting the revert ... otherwise stdout/stderr are left in O_NONBLOCK state on exit from Node in certain circumstances which results in failture of %install script as the stdout pipe of OBS overflows and returns EAGAIN
1 parent 306ce6c commit 57a47b1

File tree

2 files changed

+187
-0
lines changed

2 files changed

+187
-0
lines changed

10/21257.diff

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
https://github.com/nodejs/node/pull/21257
2+
3+
4+
diff --git a/src/node.cc b/src/node.cc
5+
index 75dbafa1ab4..7cc9131f989 100644
6+
--- a/src/node.cc
7+
+++ b/src/node.cc
8+
@@ -100,7 +100,6 @@ typedef int mode_t;
9+
#else
10+
#include <pthread.h>
11+
#include <sys/resource.h> // getrlimit, setrlimit
12+
-#include <termios.h> // tcgetattr, tcsetattr
13+
#include <unistd.h> // setuid, getuid
14+
#endif
15+
16+
@@ -173,9 +172,6 @@ using v8::Value;
17+
static Mutex process_mutex;
18+
static Mutex environ_mutex;
19+
20+
-// Safe to call more than once and from signal handlers.
21+
-inline void PlatformExit();
22+
-
23+
static bool print_eval = false;
24+
static bool force_repl = false;
25+
static bool syntax_check_only = false;
26+
@@ -886,7 +882,7 @@ void AppendExceptionLine(Environment* env,
27+
Mutex::ScopedLock lock(process_mutex);
28+
env->set_printed_error(true);
29+
30+
- PlatformExit();
31+
+ uv_tty_reset_mode();
32+
PrintErrorString("\n%s", arrow);
33+
return;
34+
}
35+
@@ -2797,7 +2793,7 @@ void SetupProcessObject(Environment* env,
36+
37+
38+
void SignalExit(int signo) {
39+
- PlatformExit();
40+
+ uv_tty_reset_mode();
41+
v8_platform.StopTracingAgent();
42+
#ifdef __FreeBSD__
43+
// FreeBSD has a nasty bug, see RegisterSignalHandler for details
44+
@@ -3629,27 +3625,6 @@ static void DebugEnd(const FunctionCallbackInfo<Value>& args) {
45+
}
46+
47+
48+
-#ifdef __POSIX__
49+
-static struct {
50+
- int flags;
51+
- bool isatty;
52+
- struct stat stat;
53+
- struct termios termios;
54+
-} stdio[1 + STDERR_FILENO];
55+
-
56+
-
57+
-inline int GetFileDescriptorFlags(int fd) {
58+
- int flags;
59+
-
60+
- do {
61+
- flags = fcntl(fd, F_GETFL);
62+
- } while (flags == -1 && errno == EINTR);
63+
-
64+
- return flags;
65+
-}
66+
-#endif // __POSIX__
67+
-
68+
-
69+
inline void PlatformInit() {
70+
#ifdef __POSIX__
71+
#if HAVE_INSPECTOR
72+
@@ -3660,9 +3635,9 @@ inline void PlatformInit() {
73+
#endif // HAVE_INSPECTOR
74+
75+
// Make sure file descriptors 0-2 are valid before we start logging anything.
76+
- for (auto& s : stdio) {
77+
- const int fd = &s - stdio;
78+
- if (fstat(fd, &s.stat) == 0)
79+
+ for (int fd = STDIN_FILENO; fd <= STDERR_FILENO; fd += 1) {
80+
+ struct stat ignored;
81+
+ if (fstat(fd, &ignored) == 0)
82+
continue;
83+
// Anything but EBADF means something is seriously wrong. We don't
84+
// have to special-case EINTR, fstat() is not interruptible.
85+
@@ -3670,8 +3645,6 @@ inline void PlatformInit() {
86+
ABORT();
87+
if (fd != open("/dev/null", O_RDWR))
88+
ABORT();
89+
- if (fstat(fd, &s.stat) != 0)
90+
- ABORT();
91+
}
92+
93+
#if HAVE_INSPECTOR
94+
@@ -3694,24 +3667,6 @@ inline void PlatformInit() {
95+
}
96+
#endif // !NODE_SHARED_MODE
97+
98+
- // Record the state of the stdio file descriptors so we can restore it
99+
- // on exit. Needs to happen before installing signal handlers because
100+
- // they make use of that information.
101+
- for (auto& s : stdio) {
102+
- const int fd = &s - stdio;
103+
- int err;
104+
-
105+
- s.flags = GetFileDescriptorFlags(fd);
106+
- CHECK_NE(s.flags, -1);
107+
-
108+
- if (!isatty(fd)) continue;
109+
- s.isatty = true;
110+
- do {
111+
- err = tcgetattr(fd, &s.termios);
112+
- } while (err == -1 && errno == EINTR);
113+
- CHECK_EQ(err, 0);
114+
- }
115+
-
116+
RegisterSignalHandler(SIGINT, SignalExit, true);
117+
RegisterSignalHandler(SIGTERM, SignalExit, true);
118+
119+
@@ -3752,49 +3707,6 @@ inline void PlatformInit() {
120+
}
121+
122+
123+
-// This function must be safe to call more than once and from signal handlers.
124+
-inline void PlatformExit() {
125+
-#ifdef __POSIX__
126+
- for (auto& s : stdio) {
127+
- const int fd = &s - stdio;
128+
-
129+
- struct stat tmp;
130+
- if (-1 == fstat(fd, &tmp)) {
131+
- CHECK_EQ(errno, EBADF); // Program closed file descriptor.
132+
- continue;
133+
- }
134+
-
135+
- bool is_same_file =
136+
- (s.stat.st_dev == tmp.st_dev && s.stat.st_ino == tmp.st_ino);
137+
- if (!is_same_file) continue; // Program reopened file descriptor.
138+
-
139+
- int flags = GetFileDescriptorFlags(fd);
140+
- CHECK_NE(flags, -1);
141+
-
142+
- // Restore the O_NONBLOCK flag if it changed.
143+
- if (O_NONBLOCK & (flags ^ s.flags)) {
144+
- flags &= ~O_NONBLOCK;
145+
- flags |= s.flags & O_NONBLOCK;
146+
-
147+
- int err;
148+
- do {
149+
- err = fcntl(fd, F_SETFL, flags);
150+
- } while (err == -1 && errno == EINTR);
151+
- CHECK_NE(err, -1);
152+
- }
153+
-
154+
- if (s.isatty) {
155+
- int err;
156+
- do {
157+
- err = tcsetattr(fd, TCSANOW, &s.termios);
158+
- } while (err == -1 && errno == EINTR);
159+
- CHECK_NE(err, -1);
160+
- }
161+
- }
162+
-#endif // __POSIX__
163+
-}
164+
-
165+
-
166+
void ProcessArgv(int* argc,
167+
const char** argv,
168+
int* exec_argc,
169+
@@ -4180,6 +4092,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
170+
171+
env.set_can_call_into_js(false);
172+
env.stop_sub_worker_contexts();
173+
+ uv_tty_reset_mode();
174+
env.RunCleanup();
175+
RunAtExit(&env);
176+
177+
@@ -4265,7 +4178,7 @@ inline int Start(uv_loop_t* event_loop,
178+
}
179+
180+
int Start(int argc, char** argv) {
181+
- atexit([] () { PlatformExit(); });
182+
+ atexit([] () { uv_tty_reset_mode(); });
183+
PlatformInit();
184+
performance::performance_node_start = PERFORMANCE_NOW();
185+

nodejs.spec.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Patch5: gyp_to_python3.patch # PATCH_FOR: 100
114114
Patch6: icu_61_namespacefix.patch # PATCH_FOR: 4, 6, 8
115115
Patch7: manual_configure.patch # PATCH_FOR: 10, 9, 8
116116
Patch8: icu_small_grouping.patch # PATCH_FOR: 9
117+
Patch9: 21257.diff # PATCH_FOR: 10
117118

118119
Patch20: CVE-2018-12115.patch # PATCH_FOR: 4
119120
Patch21: openssl_1_0_2p.patch # PATCH_FOR: 4
@@ -295,6 +296,7 @@ echo "`grep node-v%{version}.tar.xz %{S:1} | head -n1 | cut -c1-64` %{S:0}" | s
295296
%patch6 -p1
296297
%patch7 -p1
297298
%patch8 -p1
299+
%patch9 -p1 -R
298300
%patch20 -p1
299301
%patch21 -p1
300302
%patch101 -p1

0 commit comments

Comments
 (0)