Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8ed18a1

Browse filesBrowse files
bzozMylesBorins
authored andcommitted
src: ensure that fd 0-2 are valid on windows
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: #875 Fixes: #11656 PR-URL: #11863 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent ab3fdf5 commit 8ed18a1
Copy full SHA for 8ed18a1

File tree

Expand file treeCollapse file tree

3 files changed

+34
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+34
-1
lines changed
Open diff view settings
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,6 +3995,19 @@ inline void PlatformInit() {
39953995
} while (min + 1 < max);
39963996
}
39973997
#endif // __POSIX__
3998+
#ifdef _WIN32
3999+
for (int fd = 0; fd <= 2; ++fd) {
4000+
auto handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
4001+
if (handle == INVALID_HANDLE_VALUE ||
4002+
GetFileType(handle) == FILE_TYPE_UNKNOWN) {
4003+
// Ignore _close result. If it fails or not depends on used Windows
4004+
// version. We will just check _open result.
4005+
_close(fd);
4006+
if (fd != _open("nul", _O_RDWR))
4007+
ABORT();
4008+
}
4009+
}
4010+
#endif // _WIN32
39984011
}
39994012

40004013

Collapse file
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
import sys
3+
import subprocess
4+
os.close(0)
5+
os.close(1)
6+
os.close(2)
7+
exit_code = subprocess.call(sys.argv[1:], shell=False)
8+
sys.exit(exit_code)
Collapse file

‎test/parallel/test-stdio-closed.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stdio-closed.js
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ const common = require('../common');
33
const assert = require('assert');
44
const spawn = require('child_process').spawn;
55
const fs = require('fs');
6+
const path = require('path');
67

78
if (common.isWindows) {
8-
common.skip('platform not supported.');
9+
if (process.argv[2] === 'child') {
10+
process.stdin;
11+
process.stdout;
12+
process.stderr;
13+
return;
14+
}
15+
const python = process.env.PYTHON || 'python';
16+
const script = path.join(common.fixturesDir, 'spawn_closed_stdio.py');
17+
const proc = spawn(python, [script, process.execPath, __filename, 'child']);
18+
proc.on('exit', common.mustCall(function(exitCode) {
19+
assert.strictEqual(exitCode, 0);
20+
}));
921
return;
1022
}
1123

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.