Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report: use libuv calls for OS and machine info #25900

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 0 additions & 6 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down Expand Up @@ -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',
],
Expand Down Expand Up @@ -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',
],
Expand Down
122 changes: 22 additions & 100 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <cxxabi.h>
#include <dlfcn.h>
#include <inttypes.h>
#include <sys/utsname.h>
#endif

#include <fcntl.h>
Expand All @@ -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
cjihrig marked this conversation as resolved.
Show resolved Hide resolved

namespace report {
using node::arraysize;
using node::Environment;
Expand Down Expand Up @@ -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.
Expand Down