You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/04/22 07:30:34 UTC
[4/6] mesos git commit: Implemented `uname` on Windows in stout.
Implemented `uname` on Windows in stout.
Review: https://reviews.apache.org/r/46191/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3287552f
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3287552f
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3287552f
Branch: refs/heads/master
Commit: 3287552fa9e90da7952d85245bcf7b410c8203f5
Parents: 3fd64f4
Author: Alex Clemmer <cl...@gmail.com>
Authored: Thu Apr 21 11:51:37 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Thu Apr 21 22:26:22 2016 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/os.hpp | 12 ++
.../3rdparty/stout/include/stout/posix/os.hpp | 12 --
.../3rdparty/stout/include/stout/windows/os.hpp | 127 ++++++++++++++++++-
3 files changed, 138 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3287552f/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index c9576be..25e9320 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -149,6 +149,18 @@ inline void appendPaths(const std::string& newPaths)
} // namespace libraries {
+// Return the operating system name (e.g. Linux).
+inline Try<std::string> sysname()
+{
+ Try<UTSInfo> info = uname();
+ if (info.isError()) {
+ return Error(info.error());
+ }
+
+ return info.get().sysname;
+}
+
+
inline Try<std::list<Process>> processes()
{
const Try<std::set<pid_t>> pids = os::pids();
http://git-wip-us.apache.org/repos/asf/mesos/blob/3287552f/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
index e03be83..700d704 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
@@ -348,18 +348,6 @@ inline Try<Nothing> tar(const std::string& path, const std::string& archive)
}
-// Return the operating system name (e.g. Linux).
-inline Try<std::string> sysname()
-{
- Try<UTSInfo> info = uname();
- if (info.isError()) {
- return Error(info.error());
- }
-
- return info.get().sysname;
-}
-
-
// Return the OS release numbers.
inline Try<Version> release()
{
http://git-wip-us.apache.org/repos/asf/mesos/blob/3287552f/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
index ad29093..5281a2e 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
@@ -39,6 +39,96 @@
#include <stout/os/raw/environment.hpp>
namespace os {
+namespace internal {
+
+inline Try<OSVERSIONINFOEX> os_version()
+{
+ OSVERSIONINFOEX os_version;
+ os_version.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+ if (!::GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&os_version))) {
+ return WindowsError(
+ "os::internal::os_version: Call to `GetVersionEx` failed");
+ }
+
+ return os_version;
+}
+
+
+inline Try<std::string> nodename()
+{
+ // Get DNS name of the local computer. First, find the size of the output
+ // buffer.
+ DWORD size = 0;
+ if (!::GetComputerNameEx(ComputerNameDnsHostname, NULL, &size) &&
+ ::GetLastError() != ERROR_MORE_DATA) {
+ return WindowsError(
+ "os::internal::nodename: Call to `GetComputerNameEx` failed");
+ }
+
+ std::unique_ptr<char[]> name(new char[size + 1]);
+
+ if (!::GetComputerNameEx(ComputerNameDnsHostname, name.get(), &size)) {
+ return WindowsError(
+ "os::internal::nodename: Call to `GetComputerNameEx` failed");
+ }
+
+ return std::string(name.get());
+}
+
+
+inline std::string machine()
+{
+ SYSTEM_INFO system_info;
+ ::GetNativeSystemInfo(&system_info);
+
+ switch (system_info.wProcessorArchitecture) {
+ case PROCESSOR_ARCHITECTURE_AMD64:
+ return "AMD64";
+ case PROCESSOR_ARCHITECTURE_ARM:
+ return "ARM";
+ case PROCESSOR_ARCHITECTURE_IA64:
+ return "IA64";
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ return "x86";
+ default:
+ return "Unknown";
+ }
+}
+
+
+inline std::string sysname(OSVERSIONINFOEX os_version)
+{
+ switch (os_version.wProductType) {
+ case VER_NT_DOMAIN_CONTROLLER:
+ case VER_NT_SERVER:
+ return "Windows Server";
+ default:
+ return "Windows";
+ }
+}
+
+
+inline std::string release(OSVERSIONINFOEX os_version)
+{
+ return stringify(
+ Version(os_version.dwMajorVersion, os_version.dwMinorVersion, 0));
+}
+
+
+inline std::string version(OSVERSIONINFOEX os_version)
+{
+ std::string version = std::to_string(os_version.dwBuildNumber);
+
+ if (os_version.szCSDVersion[0] != '\0') {
+ version.append(" ");
+ version.append(os_version.szCSDVersion);
+ }
+
+ return version;
+}
+
+} // namespace internal {
+
// Overload of os::pids for filtering by groups and sessions. A group / session
// id of 0 will fitler on the group / session ID of the calling process.
@@ -235,8 +325,43 @@ inline Try<Memory> memory()
}
+inline Try<Version> release()
+{
+ OSVERSIONINFOEX os_version;
+ os_version.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+ if (!::GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&os_version))) {
+ return WindowsError("os::release: Call to `GetVersionEx` failed");
+ }
+
+ return Version(os_version.dwMajorVersion, os_version.dwMinorVersion, 0);
+}
+
+
// Return the system information.
-inline Try<UTSInfo> uname() = delete;
+inline Try<UTSInfo> uname()
+{
+ Try<OSVERSIONINFOEX> os_version = internal::os_version();
+ if (os_version.isError()) {
+ return Error(os_version.error());
+ }
+
+ // Add nodename to `UTSInfo` object.
+ Try<std::string> nodename = internal::nodename();
+ if (nodename.isError()) {
+ return Error(nodename.error());
+ }
+
+ // Populate `UTSInfo`.
+ UTSInfo info;
+
+ info.sysname = internal::sysname(os_version.get());
+ info.release = internal::release(os_version.get());
+ info.version = internal::version(os_version.get());
+ info.nodename = nodename.get();
+ info.machine = internal::machine();
+
+ return info;
+}
// Looks in the environment variables for the specified key and