You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/10/18 18:18:24 UTC

mesos git commit: Windows: Moved `bootId` to is own file, `stout/os/windows/bootid.hpp`.

Repository: mesos
Updated Branches:
  refs/heads/master b871a50a9 -> 0039a29e1


Windows: Moved `bootId` to is own file, `stout/os/windows/bootid.hpp`.

Review: https://reviews.apache.org/r/39213


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0039a29e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0039a29e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0039a29e

Branch: refs/heads/master
Commit: 0039a29e1cd4b359527b6501cefa64395a6da674
Parents: b871a50
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sun Oct 18 11:53:02 2015 -0400
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Sun Oct 18 12:18:07 2015 -0400

----------------------------------------------------------------------
 .../3rdparty/stout/include/Makefile.am          |  3 +
 .../3rdparty/stout/include/stout/os.hpp         | 26 +--------
 .../3rdparty/stout/include/stout/os/bootid.hpp  | 27 +++++++++
 .../stout/include/stout/os/posix/bootid.hpp     | 60 ++++++++++++++++++++
 .../stout/include/stout/os/windows/bootid.hpp   | 49 ++++++++++++++++
 5 files changed, 140 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0039a29e/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index b0d9f49..aa37a1d 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -52,12 +52,14 @@ nobase_include_HEADERS =		\
   stout/numify.hpp			\
   stout/option.hpp			\
   stout/os.hpp				\
+  stout/os/bootid.hpp			\
   stout/os/close.hpp			\
   stout/os/exists.hpp			\
   stout/os/fcntl.hpp			\
   stout/os/fork.hpp			\
   stout/os/killtree.hpp			\
   stout/os/linux.hpp			\
+  stout/os/posix/bootid.hpp		\
   stout/os/posix/exists.hpp		\
   stout/os/posix/fcntl.hpp		\
   stout/os/posix/fork.hpp		\
@@ -85,6 +87,7 @@ nobase_include_HEADERS =		\
   stout/os/pstree.hpp			\
   stout/os/sysctl.hpp			\
   stout/os/write.hpp			\
+  stout/os/windows/bootid.hpp		\
   stout/os/windows/exists.hpp		\
   stout/os/windows/fcntl.hpp		\
   stout/os/windows/fork.hpp		\

http://git-wip-us.apache.org/repos/asf/mesos/blob/0039a29e/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 7e4820f..2828c68 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -74,6 +74,7 @@
 #include <stout/unreachable.hpp>
 #include <stout/version.hpp>
 
+#include <stout/os/bootid.hpp>
 #include <stout/os/fork.hpp>
 #include <stout/os/killtree.hpp>
 #include <stout/os/ls.hpp>
@@ -86,9 +87,6 @@
 #include <stout/os/shell.hpp>
 #include <stout/os/signals.hpp>
 #include <stout/os/stat.hpp>
-#ifdef __APPLE__
-#include <stout/os/sysctl.hpp>
-#endif // __APPLE__
 #include <stout/os/write.hpp>
 
 
@@ -271,28 +269,6 @@ inline Try<Nothing> tar(const std::string& path, const std::string& archive)
 }
 
 
-inline Try<std::string> bootId()
-{
-#ifdef __linux__
-  Try<std::string> read = os::read("/proc/sys/kernel/random/boot_id");
-  if (read.isError()) {
-    return read;
-  }
-  return strings::trim(read.get());
-#elif defined(__APPLE__)
-  // For OS X, we use the boot time in seconds as a unique boot id.
-  // Although imperfect, this works quite well in practice.
-  Try<timeval> bootTime = os::sysctl(CTL_KERN, KERN_BOOTTIME).time();
-  if (bootTime.isError()) {
-    return Error(bootTime.error());
-  }
-  return stringify(bootTime.get().tv_sec);
-#else
-  return Error("Not implemented");
-#endif
-}
-
-
 // Return the operating system name (e.g. Linux).
 inline Try<std::string> sysname()
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/0039a29e/3rdparty/libprocess/3rdparty/stout/include/stout/os/bootid.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/bootid.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/bootid.hpp
new file mode 100644
index 0000000..75b4f9f
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/bootid.hpp
@@ -0,0 +1,27 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STOUT_OS_BOOTID_HPP__
+#define __STOUT_OS_BOOTID_HPP__
+
+
+// For readability, we minimize the number of #ifdef blocks in the code by
+// splitting platform specifc system calls into separate directories.
+#ifdef __WINDOWS__
+#include <stout/os/windows/bootid.hpp>
+#else
+#include <stout/os/posix/bootid.hpp>
+#endif // __WINDOWS__
+
+
+#endif // __STOUT_OS_BOOTID_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/0039a29e/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/bootid.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/bootid.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/bootid.hpp
new file mode 100644
index 0000000..3f0bad6
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/bootid.hpp
@@ -0,0 +1,60 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STOUT_OS_POSIX_BOOTID_HPP__
+#define __STOUT_OS_POSIX_BOOTID_HPP__
+
+#include <string>
+
+#include <sys/time.h>
+
+#include <stout/error.hpp>
+#include <stout/stringify.hpp>
+#include <stout/strings.hpp>
+#include <stout/try.hpp>
+
+#include <stout/os/read.hpp>
+#ifdef __APPLE__
+#include <stout/os/sysctl.hpp>
+#endif // __APPLE__
+
+
+namespace os {
+
+inline Try<std::string> bootId()
+{
+#ifdef __linux__
+  Try<std::string> read = os::read("/proc/sys/kernel/random/boot_id");
+  if (read.isError()) {
+    return read;
+  }
+  return strings::trim(read.get());
+#elif defined(__APPLE__)
+  // For OS X, we use the boot time in seconds as a unique boot id.
+  // Although imperfect, this works quite well in practice. NOTE: we can't use
+  // milliseconds here instead of seconds because the relatively high
+  // imprecision of millisecond resolution would cause `bootId` to return a
+  // different number nearly every time it was called.
+  Try<timeval> boot_time = os::sysctl(CTL_KERN, KERN_BOOTTIME).time();
+  if (boot_time.isError()) {
+    return Error(boot_time.error());
+  }
+  return stringify(boot_time.get().tv_sec);
+#else
+  return Error("Not implemented");
+#endif
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_BOOTID_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/0039a29e/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/bootid.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/bootid.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/bootid.hpp
new file mode 100644
index 0000000..5488637
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/bootid.hpp
@@ -0,0 +1,49 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STOUT_OS_WINDOWS_BOOTID_HPP__
+#define __STOUT_OS_WINDOWS_BOOTID_HPP__
+
+#include <chrono>
+#include <string>
+
+#include <stout/stringify.hpp>
+#include <stout/try.hpp>
+
+
+namespace os {
+
+inline Try<std::string> bootId()
+{
+  // NOTE: we follow the precedent of the OS X design here and use the boot
+  // time in seconds since the Unix epoch as a boot ID. See comment in
+  // `stout/os/posix/bootid.hpp` for discussion of this approach. Note also
+  // that we can't use milliseconds here instead of seconds because the
+  // relatively high imprecision of millisecond resolution would cause `bootId`
+  // to return a different number nearly every time it was called.
+
+  std::chrono::milliseconds uptime =
+    std::chrono::milliseconds(GetTickCount64());
+
+  std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
+  std::chrono::system_clock::time_point boot_time = now - uptime;
+
+  long long boot_time_secs = std::chrono::duration_cast<std::chrono::seconds>(
+      boot_time.time_since_epoch()).count();
+
+  return stringify(boot_time_secs);
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_BOOTID_HPP__