20
20
#include < fstream>
21
21
#include < iomanip>
22
22
23
- #ifndef _WIN32
24
- extern char ** environ;
25
- #endif
26
-
27
23
constexpr int NODE_REPORT_VERSION = 1 ;
28
24
constexpr int NANOS_PER_SEC = 1000 * 1000 * 1000 ;
29
25
constexpr double SEC_PER_MICROS = 1e-6 ;
@@ -552,6 +548,26 @@ static void PrintResourceUsage(JSONWriter* writer) {
552
548
553
549
// Report operating system information.
554
550
static void PrintSystemInformation (JSONWriter* writer) {
551
+ uv_env_item_t * envitems;
552
+ int envcount;
553
+ int r;
554
+
555
+ writer->json_objectstart (" environmentVariables" );
556
+
557
+ {
558
+ Mutex::ScopedLock lock (node::per_process::env_var_mutex);
559
+ r = uv_os_environ (&envitems, &envcount);
560
+ }
561
+
562
+ if (r == 0 ) {
563
+ for (int i = 0 ; i < envcount; i++)
564
+ writer->json_keyvalue (envitems[i].name , envitems[i].value );
565
+
566
+ uv_os_free_environ (envitems, envcount);
567
+ }
568
+
569
+ writer->json_objectend ();
570
+
555
571
#ifndef _WIN32
556
572
static struct {
557
573
const char * description;
@@ -576,45 +592,6 @@ static void PrintSystemInformation(JSONWriter* writer) {
576
592
{" virtual_memory_kbytes" , RLIMIT_AS}
577
593
#endif
578
594
};
579
- #endif // _WIN32
580
- writer->json_objectstart (" environmentVariables" );
581
- Mutex::ScopedLock lock (node::per_process::env_var_mutex);
582
- #ifdef _WIN32
583
- LPWSTR lpszVariable;
584
- LPWCH lpvEnv;
585
-
586
- // Get pointer to the environment block
587
- lpvEnv = GetEnvironmentStringsW ();
588
- if (lpvEnv != nullptr ) {
589
- // Variable strings are separated by null bytes,
590
- // and the block is terminated by a null byte.
591
- lpszVariable = reinterpret_cast <LPWSTR>(lpvEnv);
592
- while (*lpszVariable) {
593
- DWORD size = WideCharToMultiByte (
594
- CP_UTF8, 0 , lpszVariable, -1 , nullptr , 0 , nullptr , nullptr );
595
- char * str = new char [size];
596
- WideCharToMultiByte (
597
- CP_UTF8, 0 , lpszVariable, -1 , str, size, nullptr , nullptr );
598
- std::string env (str);
599
- int sep = env.rfind (' =' );
600
- std::string key = env.substr (0 , sep);
601
- std::string value = env.substr (sep + 1 );
602
- writer->json_keyvalue (key, value);
603
- lpszVariable += lstrlenW (lpszVariable) + 1 ;
604
- }
605
- FreeEnvironmentStringsW (lpvEnv);
606
- }
607
- writer->json_objectend ();
608
- #else
609
- std::string pair;
610
- for (char ** env = environ; *env != nullptr ; ++env) {
611
- std::string pair (*env);
612
- int separator = pair.find (' =' );
613
- std::string key = pair.substr (0 , separator);
614
- std::string str = pair.substr (separator + 1 );
615
- writer->json_keyvalue (key, str);
616
- }
617
- writer->json_objectend ();
618
595
619
596
writer->json_objectstart (" userLimits" );
620
597
struct rlimit limit;
@@ -638,7 +615,7 @@ static void PrintSystemInformation(JSONWriter* writer) {
638
615
}
639
616
}
640
617
writer->json_objectend ();
641
- #endif
618
+ #endif // _WIN32
642
619
643
620
PrintLoadedLibraries (writer);
644
621
}
0 commit comments