src: ensure that fd 0-2 are valid on windows#11863
src: ensure that fd 0-2 are valid on windows#11863bzoz wants to merge 4 commits intonodejs:masterfrom
Conversation
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: nodejs#875 Fixes: nodejs#11656
|
cc @nodejs/platform-windows |
|
CI failed on win2008 and 2012, I'll investigate. |
|
ping @bnoordhuis |
addaleax
left a comment
There was a problem hiding this comment.
Looks good from a distance ;) It’s been too long since I worked with Windows APIs to give this a proper LGTM, even if it’s only a few lines of code.
test/fixtures/spawn_closed_stdio.py
Outdated
| os.close(0) | ||
| os.close(1) | ||
| os.close(2) | ||
| cmd = sys.argv[1] + ' -e "process.stdin; process.stdout; process.stderr;"' |
There was a problem hiding this comment.
I think I would prefer it if the arguments came from the test file, i.e. you just spawn sys.argv[1] here and move the -e … bits to test-stdio-closed.js
There was a problem hiding this comment.
If you do use -e, write this as cmd = sys.argv[1:2] + ['-e', 'process.stdin; ...'] so it gets escaped properly.
src/node.cc
Outdated
| #endif // __POSIX__ | ||
| #ifdef _WIN32 | ||
| for (int fd = 0; fd <= 2; ++fd) { | ||
| auto handle = (HANDLE) _get_osfhandle(fd); |
There was a problem hiding this comment.
Can you use the appropriate C++-style cast here, whichever one that is?
test/fixtures/spawn_closed_stdio.py
Outdated
| os.close(0) | ||
| os.close(1) | ||
| os.close(2) | ||
| cmd = sys.argv[1] + ' -e "process.stdin; process.stdout; process.stderr;"' |
There was a problem hiding this comment.
If you do use -e, write this as cmd = sys.argv[1:2] + ['-e', 'process.stdin; ...'] so it gets escaped properly.
test/parallel/test-stdio-closed.js
Outdated
| if (common.isWindows) { | ||
| common.skip('platform not supported.'); | ||
| const python = process.env.PYTHON || 'python'; | ||
| const script = path.join(__dirname, '..', 'fixtures', |
There was a problem hiding this comment.
path.join(common.fixturesDir, 'spawn_closed_stdio.py')?
|
Updated, CI is green, PTAL |
| auto handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd)); | ||
| if (handle == INVALID_HANDLE_VALUE || | ||
| GetFileType(handle) == FILE_TYPE_UNKNOWN) { | ||
| _close(fd); |
There was a problem hiding this comment.
It fails on Windows 2008 and 2012 but succeeds on Windows 10. IMHO the cleanest way is to just assert that _open returned proper fd.
There was a problem hiding this comment.
Is it known why it can fail on 2008/2012 and can that be worked around at all? I'm good with this as is but I'm curious :-)
There was a problem hiding this comment.
Win2008 and 2012 fail with errno EBADF. Win 10 happily closes the handle. But regardless of that, _open works as expected on all Win versions.
There was a problem hiding this comment.
@bzoz actually, having this explanation as a comment in the source seems like a good idea to me?
|
@addaleax I've added a comment about |
|
Landed in bd496e0 |
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>
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>
|
landed in v4.x and v6x staging |
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>
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>
nodejs#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc.
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: nodejs/node#875 Fixes: nodejs/node#11656 PR-URL: nodejs/node#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>
nodejs/node#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: nodejs/node#12540 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Check that
stdin,stdoutandstderrare valid file descriptors on Windows. If not, reopen them withnulfile.This is a port of #875 for Windows.
Fixes: #11656
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
src