@@ -47,6 +47,7 @@ POP_SYS_WARNINGS
47
47
#ifndef _WIN32
48
48
#include < sys/types.h>
49
49
#include < unistd.h>
50
+ #include < sys/utsname.h>
50
51
#endif
51
52
52
53
using namespace ::mysqlx::common;
@@ -85,22 +86,109 @@ void Settings_impl::set_client_opts(const Settings_impl &opts)
85
86
set.commit ();
86
87
}
87
88
89
+ /*
90
+ Get information about OS and platform architecture.
91
+ platform - an output parameter containig the string with the
92
+ platform architecture (such as 'i386' or 'x86_64' etc)
93
+
94
+ Returns the string containing the OS type and its version.
95
+ Note: it returns the version, not the number in the name of the OS.
96
+ In Windows it will be Windows-6.3.x instead of Windows-8.1
97
+ */
98
+ std::string get_os_version_info (std::string &platform)
99
+ {
100
+ std::stringstream ver_info;
101
+ #ifdef _WIN32
102
+ HMODULE ntdll = GetModuleHandleA (" ntdll.dll" );
103
+ typedef long (NTAPI *tRtlGetVersion)(OSVERSIONINFO*);
104
+ tRtlGetVersion pRtlGetVersion = nullptr ;
105
+ OSVERSIONINFO ver;
106
+ _SYSTEM_INFO hw_info;
107
+
108
+ memset (&ver, 0 , sizeof (OSVERSIONINFO));
109
+ ver.dwOSVersionInfoSize = sizeof (sizeof (OSVERSIONINFO));
110
+
111
+ if (ntdll != nullptr )
112
+ pRtlGetVersion = (tRtlGetVersion)GetProcAddress (ntdll, " RtlGetVersion" );
113
+
114
+ if (pRtlGetVersion)
115
+ {
116
+ pRtlGetVersion (&ver);
117
+ }
118
+ else
119
+ {
120
+ PUSH_SYS_WARNINGS
121
+ DISABLE_WARNING (4996 )
122
+ if (GetVersionEx (&ver) == 0 )
123
+ ver_info << " <unknown>" ;
124
+ POP_SYS_WARNINGS
125
+ }
126
+
127
+ // Check if version info was set to <unknown> because of error
128
+ if (ver_info.str ().length () == 0 )
129
+ ver_info << " Windows-"
130
+ << ver.dwMajorVersion << " ."
131
+ << ver.dwMinorVersion << " ."
132
+ << ver.dwBuildNumber ;
133
+
134
+ GetSystemInfo (&hw_info);
135
+ switch (hw_info.wProcessorArchitecture )
136
+ {
137
+ case PROCESSOR_ARCHITECTURE_AMD64:
138
+ platform = " x86_64" ; break ;
139
+ case PROCESSOR_ARCHITECTURE_ARM:
140
+ platform = " arm" ; break ;
141
+ case PROCESSOR_ARCHITECTURE_IA64:
142
+ platform = " ia64" ; break ;
143
+ case PROCESSOR_ARCHITECTURE_INTEL:
144
+ platform = " i386" ; break ;
145
+ case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
146
+ platform = " i686" ; break ;
147
+ case PROCESSOR_ARCHITECTURE_PPC:
148
+ platform = " powerpc" ; break ;
149
+ case PROCESSOR_ARCHITECTURE_MIPS:
150
+ platform = " mips" ; break ;
151
+ case PROCESSOR_ARCHITECTURE_ALPHA:
152
+ case PROCESSOR_ARCHITECTURE_ALPHA64:
153
+ platform = " alpha" ; break ;
154
+ default :
155
+ platform = " <unknown>" ;
156
+ }
157
+
158
+ #else
159
+ struct utsname ver;
160
+ if (uname (&ver) == -1 )
161
+ {
162
+ ver_info << " <unknown>" ;
163
+ platform = " <unknown>" ;
164
+ }
165
+ else
166
+ {
167
+ ver_info << ver.sysname << " -" << ver.release ;
168
+ platform = ver.machine ;
169
+ }
170
+ #endif
171
+
172
+ return ver_info.str ();
173
+ }
174
+
88
175
void mysqlx::common::Settings_impl::Data::init_connection_attr ()
89
176
{
90
177
// Already initialized... nothing to do here!
91
178
if (!m_connection_attr.empty ())
92
179
return ;
93
180
94
181
std::string pid;
182
+ std::string platform;
95
183
#ifdef _WIN32
96
184
pid = std::to_string (GetCurrentProcessId ());
97
185
#else
98
186
pid = std::to_string (getpid ());
99
187
#endif
100
188
m_connection_attr[" _pid" ] = pid;
101
189
102
- m_connection_attr[" _platform " ] = MACHINE_TYPE ;
103
- m_connection_attr[" _os " ] = SYSTEM_TYPE ;
190
+ m_connection_attr[" _os " ] = get_os_version_info (platform) ;
191
+ m_connection_attr[" _platform " ] = platform ;
104
192
m_connection_attr[" _source_host" ] =
105
193
cdk::foundation::connection::get_local_hostname ();
106
194
m_connection_attr[" _client_name" ] = PACKAGE_NAME;
0 commit comments