diff --git a/doc/api/report.md b/doc/api/report.md index 8e8289a6fb7ec1..d41fca20ef5a74 100644 --- a/doc/api/report.md +++ b/doc/api/report.md @@ -57,8 +57,11 @@ is provided below for reference. "release": { "name": "node" }, - "osVersion": "Linux 3.10.0-862.el7.x86_64 #1 SMP Wed Mar 21 18:14:51 EDT 2018", - "machine": "test_machine x86_64" + "osName": "Linux", + "osRelease": "3.10.0-862.el7.x86_64", + "osVersion": "#1 SMP Wed Mar 21 18:14:51 EDT 2018", + "osMachine": "x86_64", + "host": "test_machine" }, "javascriptStack": { "message": "Error: *** test-exception.js: throwing uncaught Error", diff --git a/node.gyp b/node.gyp index 6b7cbe26f34713..e3ff9da6b95b28 100644 --- a/node.gyp +++ b/node.gyp @@ -334,13 +334,11 @@ ['OS=="win"', { 'libraries': [ 'dbghelp.lib', - 'Netapi32.lib', 'PsApi.lib', 'Ws2_32.lib', ], 'dll_files': [ 'dbghelp.dll', - 'Netapi32.dll', 'PsApi.dll', 'Ws2_32.dll', ], @@ -676,13 +674,11 @@ ['OS=="win"', { 'libraries': [ 'dbghelp.lib', - 'Netapi32.lib', 'PsApi.lib', 'Ws2_32.lib', ], 'dll_files': [ 'dbghelp.dll', - 'Netapi32.dll', 'PsApi.dll', 'Ws2_32.dll', ], @@ -1041,13 +1037,11 @@ ['OS=="win"', { 'libraries': [ 'dbghelp.lib', - 'Netapi32.lib', 'PsApi.lib', 'Ws2_32.lib', ], 'dll_files': [ 'dbghelp.dll', - 'Netapi32.dll', 'PsApi.dll', 'Ws2_32.dll', ], diff --git a/src/node_report.cc b/src/node_report.cc index 08d3642e7a3891..d10db1c97bc8b1 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -28,7 +28,6 @@ #include #include #include -#include #endif #include @@ -48,6 +47,15 @@ extern char** environ; #endif +#ifdef __POSIX__ +# include // MAXHOSTNAMELEN on Solaris. +# include // MAXHOSTNAMELEN on Linux and the BSDs. +#endif // __POSIX__ + +#ifndef MAXHOSTNAMELEN +# define MAXHOSTNAMELEN 256 +#endif // MAXHOSTNAMELEN + namespace report { using node::arraysize; using node::Environment; @@ -351,107 +359,21 @@ static void PrintVersionInformation(JSONWriter* writer) { // Report release metadata. PrintRelease(writer); - // Report operating system and machine information (Windows) -#ifdef _WIN32 - { - // Level 101 to obtain the server name, type, and associated details. - // ref: https://docs.microsoft.com/en-us/windows/desktop/ - // api/lmserver/nf-lmserver-netservergetinfo - const DWORD level = 101; - LPSERVER_INFO_101 os_info = nullptr; - NET_API_STATUS nStatus = - NetServerGetInfo(nullptr, level, reinterpret_cast(&os_info)); - if (nStatus == NERR_Success) { - LPSTR os_name = "Windows"; - const DWORD major = os_info->sv101_version_major & MAJOR_VERSION_MASK; - const DWORD type = os_info->sv101_type; - const bool isServer = (type & SV_TYPE_DOMAIN_CTRL) || - (type & SV_TYPE_DOMAIN_BAKCTRL) || - (type & SV_TYPE_SERVER_NT); - switch (major) { - case 5: - switch (os_info->sv101_version_minor) { - case 0: - os_name = "Windows 2000"; - break; - default: - os_name = (isServer ? "Windows Server 2003" : "Windows XP"); - } - break; - case 6: - switch (os_info->sv101_version_minor) { - case 0: - os_name = (isServer ? "Windows Server 2008" : "Windows Vista"); - break; - case 1: - os_name = (isServer ? "Windows Server 2008 R2" : "Windows 7"); - break; - case 2: - os_name = (isServer ? "Windows Server 2012" : "Windows 8"); - break; - case 3: - os_name = (isServer ? "Windows Server 2012 R2" : "Windows 8.1"); - break; - default: - os_name = (isServer ? "Windows Server" : "Windows Client"); - } - break; - case 10: - os_name = (isServer ? "Windows Server 2016" : "Windows 10"); - break; - default: - os_name = (isServer ? "Windows Server" : "Windows Client"); - } - writer->json_keyvalue("osVersion", os_name); - - // Convert and report the machine name and comment fields - // (these are LPWSTR types) - size_t count; - char name_buf[256]; - wcstombs_s( - &count, name_buf, sizeof(name_buf), os_info->sv101_name, _TRUNCATE); - if (os_info->sv101_comment != nullptr) { - char comment_buf[256]; - wcstombs_s(&count, - comment_buf, - sizeof(comment_buf), - os_info->sv101_comment, - _TRUNCATE); - buf << name_buf << " " << comment_buf; - writer->json_keyvalue("machine", buf.str()); - buf.flush(); - } else { - writer->json_keyvalue("machine", name_buf); - } + // Report operating system and machine information + uv_utsname_t os_info; - if (os_info != nullptr) { - NetApiBufferFree(os_info); - } - } else { - // NetServerGetInfo() failed, fallback to use GetComputerName() instead - TCHAR machine_name[256]; - DWORD machine_name_size = 256; - writer->json_keyvalue("osVersion", "Windows"); - if (GetComputerName(machine_name, &machine_name_size)) { - writer->json_keyvalue("machine", machine_name); - } - } - } -#else - // Report operating system and machine information (Unix/OSX) - struct utsname os_info; - if (uname(&os_info) >= 0) { -#ifdef _AIX - buf << os_info.sysname << " " << os_info.version << "." << os_info.release; -#else - buf << os_info.sysname << " " << os_info.release << " " << os_info.version; -#endif /* _AIX */ - writer->json_keyvalue("osVersion", buf.str()); - buf.str(""); - buf << os_info.nodename << " " << os_info.machine; - writer->json_keyvalue("machine", buf.str()); + if (uv_os_uname(&os_info) == 0) { + writer->json_keyvalue("osName", os_info.sysname); + writer->json_keyvalue("osRelease", os_info.release); + writer->json_keyvalue("osVersion", os_info.version); + writer->json_keyvalue("osMachine", os_info.machine); } -#endif + + char host[MAXHOSTNAMELEN + 1]; + size_t host_size = sizeof(host); + + if (uv_os_gethostname(host, &host_size) == 0) + writer->json_keyvalue("host", host); } // Report the JavaScript stack.