|
28 | 28 | #include <cxxabi.h>
|
29 | 29 | #include <dlfcn.h>
|
30 | 30 | #include <inttypes.h>
|
31 |
| -#include <sys/utsname.h> |
32 | 31 | #endif
|
33 | 32 |
|
34 | 33 | #include <fcntl.h>
|
|
48 | 47 | extern char** environ;
|
49 | 48 | #endif
|
50 | 49 |
|
| 50 | +#ifdef __POSIX__ |
| 51 | +# include <netdb.h> // MAXHOSTNAMELEN on Solaris. |
| 52 | +# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs. |
| 53 | +#endif // __POSIX__ |
| 54 | + |
| 55 | +#ifndef MAXHOSTNAMELEN |
| 56 | +# define MAXHOSTNAMELEN 256 |
| 57 | +#endif // MAXHOSTNAMELEN |
| 58 | + |
51 | 59 | namespace report {
|
52 | 60 | using node::arraysize;
|
53 | 61 | using node::Environment;
|
@@ -351,107 +359,21 @@ static void PrintVersionInformation(JSONWriter* writer) {
|
351 | 359 | // Report release metadata.
|
352 | 360 | PrintRelease(writer);
|
353 | 361 |
|
354 |
| - // Report operating system and machine information (Windows) |
355 |
| -#ifdef _WIN32 |
356 |
| - { |
357 |
| - // Level 101 to obtain the server name, type, and associated details. |
358 |
| - // ref: https://docs.microsoft.com/en-us/windows/desktop/ |
359 |
| - // api/lmserver/nf-lmserver-netservergetinfo |
360 |
| - const DWORD level = 101; |
361 |
| - LPSERVER_INFO_101 os_info = nullptr; |
362 |
| - NET_API_STATUS nStatus = |
363 |
| - NetServerGetInfo(nullptr, level, reinterpret_cast<LPBYTE*>(&os_info)); |
364 |
| - if (nStatus == NERR_Success) { |
365 |
| - LPSTR os_name = "Windows"; |
366 |
| - const DWORD major = os_info->sv101_version_major & MAJOR_VERSION_MASK; |
367 |
| - const DWORD type = os_info->sv101_type; |
368 |
| - const bool isServer = (type & SV_TYPE_DOMAIN_CTRL) || |
369 |
| - (type & SV_TYPE_DOMAIN_BAKCTRL) || |
370 |
| - (type & SV_TYPE_SERVER_NT); |
371 |
| - switch (major) { |
372 |
| - case 5: |
373 |
| - switch (os_info->sv101_version_minor) { |
374 |
| - case 0: |
375 |
| - os_name = "Windows 2000"; |
376 |
| - break; |
377 |
| - default: |
378 |
| - os_name = (isServer ? "Windows Server 2003" : "Windows XP"); |
379 |
| - } |
380 |
| - break; |
381 |
| - case 6: |
382 |
| - switch (os_info->sv101_version_minor) { |
383 |
| - case 0: |
384 |
| - os_name = (isServer ? "Windows Server 2008" : "Windows Vista"); |
385 |
| - break; |
386 |
| - case 1: |
387 |
| - os_name = (isServer ? "Windows Server 2008 R2" : "Windows 7"); |
388 |
| - break; |
389 |
| - case 2: |
390 |
| - os_name = (isServer ? "Windows Server 2012" : "Windows 8"); |
391 |
| - break; |
392 |
| - case 3: |
393 |
| - os_name = (isServer ? "Windows Server 2012 R2" : "Windows 8.1"); |
394 |
| - break; |
395 |
| - default: |
396 |
| - os_name = (isServer ? "Windows Server" : "Windows Client"); |
397 |
| - } |
398 |
| - break; |
399 |
| - case 10: |
400 |
| - os_name = (isServer ? "Windows Server 2016" : "Windows 10"); |
401 |
| - break; |
402 |
| - default: |
403 |
| - os_name = (isServer ? "Windows Server" : "Windows Client"); |
404 |
| - } |
405 |
| - writer->json_keyvalue("osVersion", os_name); |
406 |
| - |
407 |
| - // Convert and report the machine name and comment fields |
408 |
| - // (these are LPWSTR types) |
409 |
| - size_t count; |
410 |
| - char name_buf[256]; |
411 |
| - wcstombs_s( |
412 |
| - &count, name_buf, sizeof(name_buf), os_info->sv101_name, _TRUNCATE); |
413 |
| - if (os_info->sv101_comment != nullptr) { |
414 |
| - char comment_buf[256]; |
415 |
| - wcstombs_s(&count, |
416 |
| - comment_buf, |
417 |
| - sizeof(comment_buf), |
418 |
| - os_info->sv101_comment, |
419 |
| - _TRUNCATE); |
420 |
| - buf << name_buf << " " << comment_buf; |
421 |
| - writer->json_keyvalue("machine", buf.str()); |
422 |
| - buf.flush(); |
423 |
| - } else { |
424 |
| - writer->json_keyvalue("machine", name_buf); |
425 |
| - } |
| 362 | + // Report operating system and machine information |
| 363 | + uv_utsname_t os_info; |
426 | 364 |
|
427 |
| - if (os_info != nullptr) { |
428 |
| - NetApiBufferFree(os_info); |
429 |
| - } |
430 |
| - } else { |
431 |
| - // NetServerGetInfo() failed, fallback to use GetComputerName() instead |
432 |
| - TCHAR machine_name[256]; |
433 |
| - DWORD machine_name_size = 256; |
434 |
| - writer->json_keyvalue("osVersion", "Windows"); |
435 |
| - if (GetComputerName(machine_name, &machine_name_size)) { |
436 |
| - writer->json_keyvalue("machine", machine_name); |
437 |
| - } |
438 |
| - } |
439 |
| - } |
440 |
| -#else |
441 |
| - // Report operating system and machine information (Unix/OSX) |
442 |
| - struct utsname os_info; |
443 |
| - if (uname(&os_info) >= 0) { |
444 |
| -#ifdef _AIX |
445 |
| - buf << os_info.sysname << " " << os_info.version << "." << os_info.release; |
446 |
| -#else |
447 |
| - buf << os_info.sysname << " " << os_info.release << " " << os_info.version; |
448 |
| -#endif /* _AIX */ |
449 |
| - writer->json_keyvalue("osVersion", buf.str()); |
450 |
| - buf.str(""); |
451 |
| - buf << os_info.nodename << " " << os_info.machine; |
452 |
| - writer->json_keyvalue("machine", buf.str()); |
| 365 | + if (uv_os_uname(&os_info) == 0) { |
| 366 | + writer->json_keyvalue("osName", os_info.sysname); |
| 367 | + writer->json_keyvalue("osRelease", os_info.release); |
| 368 | + writer->json_keyvalue("osVersion", os_info.version); |
| 369 | + writer->json_keyvalue("osMachine", os_info.machine); |
453 | 370 | }
|
454 |
| -#endif |
| 371 | + |
| 372 | + char host[MAXHOSTNAMELEN + 1]; |
| 373 | + size_t host_size = sizeof(host); |
| 374 | + |
| 375 | + if (uv_os_gethostname(host, &host_size) == 0) |
| 376 | + writer->json_keyvalue("host", host); |
455 | 377 | }
|
456 | 378 |
|
457 | 379 | // Report the JavaScript stack.
|
|
0 commit comments