diff options
author | cjihrig <cjihrig@gmail.com> | 2019-02-02 14:36:16 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-02-05 08:56:16 -0500 |
commit | 9bbe29dcce8ee7830e5589a407e56e9cfcfc2129 (patch) | |
tree | 4fdcc8c8613c436c66b14086bf2ac81016ebca3c /src/node_report.cc | |
parent | 50f9062396f2b30e33f75aeafa72ef2740ad6f16 (diff) | |
download | android-node-v8-9bbe29dcce8ee7830e5589a407e56e9cfcfc2129.tar.gz android-node-v8-9bbe29dcce8ee7830e5589a407e56e9cfcfc2129.tar.bz2 android-node-v8-9bbe29dcce8ee7830e5589a407e56e9cfcfc2129.zip |
report: use libuv calls for OS and machine info
PR-URL: https://github.com/nodejs/node/pull/25900
Fixes: https://github.com/nodejs/node/issues/25843
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Diffstat (limited to 'src/node_report.cc')
-rw-r--r-- | src/node_report.cc | 122 |
1 files changed, 22 insertions, 100 deletions
diff --git a/src/node_report.cc b/src/node_report.cc index 08d3642e7a..d10db1c97b 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -28,7 +28,6 @@ #include <cxxabi.h> #include <dlfcn.h> #include <inttypes.h> -#include <sys/utsname.h> #endif #include <fcntl.h> @@ -48,6 +47,15 @@ extern char** environ; #endif +#ifdef __POSIX__ +# include <netdb.h> // MAXHOSTNAMELEN on Solaris. +# include <sys/param.h> // 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<LPBYTE*>(&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. |