From eaf474cc5dcf2c915cf1a91c4742df57ceb4ae2d Mon Sep 17 00:00:00 2001 From: Yihong Wang Date: Wed, 7 Mar 2018 12:25:26 -0800 Subject: [PATCH] test: shared lib build doesn't handle SIGPIPE For shared lib build, we leave the signal handling for embedding users. In these two test cases: - `parallel/test-process-external-stdio-close-spawn` - `parallel/test-process-external-stdio-close` The pipe is used for stdout and is destroied before child process uses it for logging. So the node executble that uses shared lib build receives SIGPIPE and the child process ends. This change ignores the SIGPIPE in node_main.cc for shared lib case. Refs: https://github.com/nodejs/node/issues/18535 Signed-off-by: Yihong Wang PR-URL: https://github.com/nodejs/node/pull/19211 Refs: https://github.com/nodejs/node/issues/18535 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Gireesh Punathil Signed-off-by: Beth Griggs --- node.gyp | 20 +++----------------- node.gypi | 18 ++++++++++++++++++ src/node_main.cc | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/node.gyp b/node.gyp index 2967b5efc3def5..91a0590993b973 100644 --- a/node.gyp +++ b/node.gyp @@ -178,6 +178,9 @@ 'sources': [ 'src/node_main.cc' ], + 'includes': [ + 'node.gypi' + ], 'include_dirs': [ 'src', 'deps/v8/include', @@ -195,9 +198,6 @@ }], [ 'node_intermediate_lib_type=="static_library" and ' 'node_shared=="false"', { - 'includes': [ - 'node.gypi' - ], 'xcode_settings': { 'OTHER_LDFLAGS': [ '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)' @@ -439,22 +439,8 @@ ], }], ], - 'defines!': [ - 'NODE_PLATFORM="win"', - ], - 'defines': [ - 'FD_SETSIZE=1024', - # we need to use node's preferred "win32" rather than gyp's preferred "win" - 'NODE_PLATFORM="win32"', - # Stop from defining macros that conflict with - # std::min() and std::max(). We don't use (much) - # but we still inherit it from uv.h. - 'NOMINMAX', - '_UNICODE=1', - ], 'libraries': [ '-lpsapi.lib' ] }, { # POSIX - 'defines': [ '__POSIX__' ], 'sources': [ 'src/backtrace_posix.cc' ], }], [ 'node_use_etw=="true"', { diff --git a/node.gypi b/node.gypi index 82953ee9ff9af4..3faffdfff3366f 100644 --- a/node.gypi +++ b/node.gypi @@ -37,6 +37,24 @@ 'NODE_SHARED_MODE', ], }], + [ 'OS=="win"', { + 'defines!': [ + 'NODE_PLATFORM="win"', + ], + 'defines': [ + 'FD_SETSIZE=1024', + # we need to use node's preferred "win32" rather than gyp's preferred "win" + 'NODE_PLATFORM="win32"', + # Stop from defining macros that conflict with + # std::min() and std::max(). We don't use (much) + # but we still inherit it from uv.h. + 'NOMINMAX', + '_UNICODE=1', + ], + }, { # POSIX + 'defines': [ '__POSIX__' ], + }], + [ 'node_enable_d8=="true"', { 'dependencies': [ 'deps/v8/src/d8.gyp:d8' ], }], diff --git a/src/node_main.cc b/src/node_main.cc index 7ab612d53e500a..8907c47ae0ea4c 100644 --- a/src/node_main.cc +++ b/src/node_main.cc @@ -82,12 +82,30 @@ int wmain(int argc, wchar_t *wargv[]) { #endif // __LP64__ extern char** environ; #endif // __linux__ +#if defined(__POSIX__) && defined(NODE_SHARED_MODE) +#include +#include +#endif namespace node { extern bool linux_at_secure; } // namespace node int main(int argc, char *argv[]) { +#if defined(__POSIX__) && defined(NODE_SHARED_MODE) + // In node::PlatformInit(), we squash all signal handlers for non-shared lib + // build. In order to run test cases against shared lib build, we also need + // to do the same thing for shared lib build here, but only for SIGPIPE for + // now. If node::PlatformInit() is moved to here, then this section could be + // removed. + { + struct sigaction act; + memset(&act, 0, sizeof(act)); + act.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &act, nullptr); + } +#endif + #if defined(__linux__) char** envp = environ; while (*envp++ != nullptr) {}