You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ka...@apache.org on 2016/05/11 22:24:55 UTC
[33/50] [abbrv] mesos git commit: Moved stout from
libprocess/3rdparty/ to 3rdparty/.
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/synchronized.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/synchronized.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/synchronized.hpp
deleted file mode 100644
index e347807..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/synchronized.hpp
+++ /dev/null
@@ -1,224 +0,0 @@
-// 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_SYNCHRONIZED_HPP__
-#define __STOUT_SYNCHRONIZED_HPP__
-
-#include <atomic>
-#include <condition_variable>
-#include <mutex>
-#include <type_traits>
-
-#include <glog/logging.h>
-
-#include <stout/preprocessor.hpp>
-
-// An RAII class for the 'synchronized(m)' macro.
-template <typename T>
-class Synchronized
-{
-public:
- explicit Synchronized(T* t, void (*acquire)(T*), void (*release)(T*))
- : t_(CHECK_NOTNULL(t)), release_(release)
- {
- acquire(t_);
- }
-
- ~Synchronized() { release_(t_); }
-
- // NOTE: 'false' being returned here has no significance.
- // Refer to the NOTE for 'synchronized' at the bottom for why.
- explicit operator bool() const { return false; }
-
-private:
- T* t_;
-
- void (*release_)(T*);
-};
-
-
-// The generic version handles mutexes which have 'lock' and 'unlock'
-// member functions such as 'std::mutex' and 'std::recursive_mutex'.
-template <typename T>
-Synchronized<T> synchronize(T* t)
-{
- return Synchronized<T>(
- t,
- [](T* t) { t->lock(); },
- [](T* t) { t->unlock(); }
- );
-}
-
-
-// An overload of the 'synchronize' function for 'std::atomic_flag'.
-inline Synchronized<std::atomic_flag> synchronize(std::atomic_flag* lock)
-{
- return Synchronized<std::atomic_flag>(
- lock,
- [](std::atomic_flag* lock) {
- while (lock->test_and_set(std::memory_order_acquire)) {}
- },
- [](std::atomic_flag* lock) {
- lock->clear(std::memory_order_release);
- }
- );
-}
-
-
-template <typename T>
-T* synchronized_get_pointer(T** t)
-{
- return *CHECK_NOTNULL(t);
-}
-
-
-template <typename T>
-T* synchronized_get_pointer(T* t)
-{
- return t;
-}
-
-
-// Macros to help generate "unique" identifiers for the
-// synchronization variable name and label. The line number gets
-// embedded which makes it unique enough, but not absolutely unique.
-// It shouldn't be a problem however, since it's very unlikely that
-// anyone would place multiple 'synchronized' blocks on one line.
-#define SYNCHRONIZED_PREFIX CAT(__synchronizer_, __LINE__)
-#define SYNCHRONIZED_VAR CAT(SYNCHRONIZED_PREFIX, _var__)
-#define SYNCHRONIZED_LABEL CAT(SYNCHRONIZED_PREFIX, _label__)
-
-
-// A macro for acquiring a scoped 'guard' on any type that can satisfy
-// the 'Synchronized' interface. We support 'std::mutex',
-// 'std::recursive_mutex' and 'std::atomic_flag' by default.
-//
-// Example usage:
-// std::mutex m;
-// synchronized (m) {
-// // Do something under the lock.
-// }
-//
-// You can easily extend support for your synchronization primitive
-// here, by overloading the 'synchronize' function.
-//
-// Example overload:
-// inline Synchronized<bufferevent> synchronize(bufferevent* bev)
-// {
-// return Synchronized<bufferevent>(
-// bev,
-// [](bufferevent* bev) { bufferevent_lock(bev); },
-// [](bufferevent* bev) { bufferevent_unlock(bev); },
-// );
-// }
-//
-// How it works: An instance of the synchronization primitive is
-// constructed inside the 'condition' of if statement. This variable
-// stays alive for the lifetime of the block. The trick with 'goto',
-// 'else' and the label allows the compiler to figure out that the
-// synchronized block will always execute. This allows us to return
-// within the synchronized block and avoid the
-// 'control reaches the end of a non-void function' warning.
-// Note that the variable declared inside the 'condition' of an if
-// statement is guaranteed to live through the 'else' clause as well.
-//
-// From Section 6.4.3:
-// A name introduced by a declaration in a condition (either
-// introduced by the decl-specifier-seq or the declarator of the
-// condition) is in scope from its point of declaration until the
-// end of the substatements controlled by the condition.
-#define synchronized(m) \
- if (Synchronized<typename std::remove_pointer<decltype(m)>::type> \
- SYNCHRONIZED_VAR = ::synchronize(::synchronized_get_pointer(&m))) { \
- goto SYNCHRONIZED_LABEL; \
- } else SYNCHRONIZED_LABEL:
-
-
-/**
- * Waits on the condition variable associated with 'lock' which has
- * already been synchronized. Currently, the only supported
- * implementation is for 'std::condition_variable' associated with a
- * 'std::mutex'.
- *
- * @param cv The condition variable.
- * @param lock The lock associated with the condition variable.
- *
- * @pre 'lock' is already owned by the calling thread.
- * @post 'lock' is still owned by the calling thread.
- *
- * @return Nothing.
- */
-template <typename CV, typename Lock>
-void synchronized_wait(CV* cv, Lock* lock);
-
-
-/**
- * Waits on the 'std::condition_variable' associated with 'std::mutex'
- * which has already been synchronized. We provide this specialization
- * since 'std::condition_variable::wait' only works with
- * 'std::unique_lock<std::mutex>'.
- *
- * @example
- * std::condition_variable cv;
- * std::mutex m;
- * synchronized (m) { // lock 'm'.
- * // ...
- * synchronized_wait(cv, m); // unlock/lock 'm'.
- * // ...
- * } // unlock 'm'.
- *
- * @param cv The 'std::condition_variable'.
- * @param mutex The 'std::mutex' associated with the
- * 'std::condition_variable'.
- *
- * @pre 'mutex' is already owned by the calling thread.
- * @post 'mutex' is still owned by the calling thread.
- *
- * @return Nothing.
- */
-template <>
-inline void synchronized_wait(std::condition_variable* cv, std::mutex* mutex)
-{
- CHECK_NOTNULL(cv);
- CHECK_NOTNULL(mutex);
-
- // Since the pre-condition is that 'mutex' is already owned by the
- // calling thread, we use 'std::adopt_lock' to adopt the mutex
- // rather than trying to lock it ourselves.
- std::unique_lock<std::mutex> lock(*mutex, std::adopt_lock);
-
- // On entrance, 'std::condition_variable::wait' releases 'mutex'.
- // On exit, 'std::condition_variable::wait' re-acquires 'mutex'.
- cv->wait(lock);
-
- // At this point, the 'mutex' has been acquired. Since the
- // post-condition is that 'mutex' is still owned by the calling
- // thread, we use 'release' in order to prevent 'std::unique_lock'
- // from unlocking the 'mutex'.
- lock.release();
-}
-
-
-/**
- * There is a known bug around 'std::condition_variable_any' in
- * 'libstdc++' distributed 'devtoolset-2', and also general issues
- * around the use of 'std::condition_variable_any' with
- * 'std::recursive_mutex'. Hence, this function is currently deleted
- * until both issues are resolved.
- *
- * @see https://rhn.redhat.com/errata/RHBA-2014-1035.html
- * @see http://stackoverflow.com/questions/11752155/behavior-of-condition-variable-any-when-used-with-a-recursive-mutex
- */
-template <typename Lock>
-void synchronized_wait(std::condition_variable_any* cv, Lock* lock) = delete;
-
-#endif // __STOUT_SYNCHRONIZED_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/tests/utils.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/tests/utils.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/tests/utils.hpp
deleted file mode 100644
index 4e5359c..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/tests/utils.hpp
+++ /dev/null
@@ -1,66 +0,0 @@
-// 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_TESTS_UTILS_HPP__
-#define __STOUT_TESTS_UTILS_HPP__
-
-#include <string>
-
-#include <gtest/gtest.h>
-
-#include <stout/gtest.hpp>
-#include <stout/try.hpp>
-
-#include <stout/os/chdir.hpp>
-#include <stout/os/getcwd.hpp>
-#include <stout/os/mkdtemp.hpp>
-#include <stout/os/rmdir.hpp>
-
-class TemporaryDirectoryTest : public ::testing::Test
-{
-protected:
- virtual void SetUp()
- {
- // Save the current working directory.
- cwd = os::getcwd();
-
- // Create a temporary directory for the test.
- Try<std::string> directory = os::mkdtemp();
-
- ASSERT_SOME(directory) << "Failed to mkdtemp";
-
- sandbox = directory.get();
-
- // Run the test out of the temporary directory we created.
- ASSERT_SOME(os::chdir(sandbox.get()))
- << "Failed to chdir into '" << sandbox.get() << "'";
- }
-
- virtual void TearDown()
- {
- // Return to previous working directory and cleanup the sandbox.
- ASSERT_SOME(os::chdir(cwd));
-
- if (sandbox.isSome()) {
- ASSERT_SOME(os::rmdir(sandbox.get()));
- }
- }
-
- // A temporary directory for test purposes.
- // Not to be confused with the "sandbox" that tasks are run in.
- Option<std::string> sandbox;
-
-private:
- std::string cwd;
-};
-
-#endif // __STOUT_TESTS_UTILS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/thread_local.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/thread_local.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/thread_local.hpp
deleted file mode 100644
index 7ffc809..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/thread_local.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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_THREAD_LOCAL_HPP__
-#define __STOUT_THREAD_LOCAL_HPP__
-
-// A wrapper around the thread local storage attribute. The default
-// clang on OSX does not support the c++11 standard `thread_local`
-// intentionally until a higher performance implementation is
-// released. See https://devforums.apple.com/message/1079348#1079348
-// Until then, we use `__thread` on OSX instead.
-// We required that THREAD_LOCAL is only used with POD types as this
-// is a requirement of `__thread`.
-#ifdef __APPLE__
-#define THREAD_LOCAL __thread
-#else
-#define THREAD_LOCAL thread_local
-#endif
-
-#endif // __STOUT_THREAD_LOCAL_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
deleted file mode 100644
index 89dedec..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
+++ /dev/null
@@ -1,114 +0,0 @@
-// 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_TRY_HPP__
-#define __STOUT_TRY_HPP__
-
-#include <assert.h>
-
-#include <iostream>
-#include <string>
-
-#include <stout/abort.hpp>
-#include <stout/error.hpp>
-#include <stout/option.hpp>
-#include <stout/some.hpp>
-
-// This class can represent only one of these states at a time:
-// 1) A value of T.
-// 2) An error state, with a corresponding error string.
-// Calling 'isSome' will return true if it stores a value, in which
-// case calling 'get' will return a constant reference to the T
-// stored. Calling 'isError' will return true if it stores an error,
-// in which case calling 'error' will return the error string.
-template <typename T, typename E = Error>
-class Try
-{
-public:
- static_assert(
- std::is_base_of<Error, E>::value,
- "An error type must be, or be inherited from 'Error'.");
-
- static Try some(const T& t) { return Try(t); }
- static Try error(const E& e) { return Try(e); }
-
- Try(const T& t)
- : data(Some(t)) {}
-
- template <
- typename U,
- typename = typename std::enable_if<
- std::is_constructible<T, const U&>::value>::type>
- Try(const U& u) : data(Some(u)) {}
-
- Try(const E& error) : error_(error) {}
-
- // TODO(bmahler): Add move constructor.
-
- // We don't need to implement these because we are leveraging
- // Option<T>.
- Try(const Try& that) = default;
- ~Try() = default;
- Try& operator=(const Try& that) = default;
-
- // 'isSome' and 'isError' are mutually exclusive. They correspond
- // to the underlying state of the Option.
- bool isSome() const { return data.isSome(); }
- bool isError() const { return data.isNone(); }
-
- const T& get() const
- {
- if (!data.isSome()) {
- assert(error_.isSome());
- ABORT("Try::get() but state == ERROR: " + error_.get().message);
- }
- return data.get();
- }
-
- T& get()
- {
- return const_cast<T&>(static_cast<const Try&>(*this).get());
- }
-
- const T* operator->() const { return &get(); }
- T* operator->() { return &get(); }
-
- // NOTE: This function is intended to return the error of type `E`.
- // However, we return a `std::string` if `E` == `Error` since that's what it
- // used to return, and it's the only data that `Error` holds anyway.
- const typename std::conditional<
- std::is_same<E, Error>::value, std::string, E>::type& error() const
- {
- assert(data.isNone());
- assert(error_.isSome());
- return error_impl(error_.get());
- }
-
-private:
- static const std::string& error_impl(const Error& err) { return err.message; }
-
- template <typename Err>
- static const Err& error_impl(const Err& err) { return err; }
-
- // We leverage Option<T> to avoid dynamic allocation of T. This
- // means that the storage for T will be included in this object
- // (Try<T>). Since Option<T> keeps track of whether a value is
- // stored, we just ask it when we want to know whether we are
- // storing a value or an error. Another advantage of leveraging
- // Option<T> is that it takes care of all the manual construction
- // and destruction. This makes the code for Try<T> really simple!
- Option<T> data;
- Option<E> error_;
-};
-
-
-#endif // __STOUT_TRY_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/unimplemented.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/unimplemented.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/unimplemented.hpp
deleted file mode 100644
index ab6caa8..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/unimplemented.hpp
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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_UNIMPLEMENTED_HPP__
-#define __STOUT_UNIMPLEMENTED_HPP__
-
-// If the project is configured to use static assertions for
-// unimplemented functions.
-#ifdef ENABLE_STATIC_UNIMPLEMENTED
-#define UNIMPLEMENTED static_assert(false, "Unimplemented function");
-#else
-// Otherwise we display an error message at runtime and abort.
-
-#include <stdlib.h>
-
-#include <iostream>
-
-#include <stout/attributes.hpp>
-
-#define UNIMPLEMENTED Unimplemented(__func__, __FILE__, __LINE__)
-
-NORETURN inline void Unimplemented(
- const char* function,
- const char* file,
- const int line)
-{
- std::cerr << "Reached unimplemented function '" << function << "' at "
- << file << ':' << line << std::endl;
- abort();
-}
-#endif
-
-#endif // __STOUT_UNIMPLEMENTED_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/unreachable.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/unreachable.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/unreachable.hpp
deleted file mode 100644
index d4b3bb0..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/unreachable.hpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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_UNREACHABLE_HPP__
-#define __STOUT_UNREACHABLE_HPP__
-
-#include <iostream>
-
-#include <stout/abort.hpp>
-#include <stout/attributes.hpp>
-
-
-#define UNREACHABLE() Unreachable(__FILE__, __LINE__)
-
-
-inline NORETURN void Unreachable(const char* file, int line)
-{
- std::cerr << "Reached unreachable statement at " << file << ':'
- << line << std::endl;
- abort();
-}
-
-
-#endif // __STOUT_UNREACHABLE_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/utils.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/utils.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/utils.hpp
deleted file mode 100644
index 82cab83..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/utils.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// 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_UTILS_HPP__
-#define __STOUT_UTILS_HPP__
-
-#include <algorithm>
-
-namespace utils {
-
-template <typename T>
-T copy(const T& t) { return t; }
-
-
-template <typename T, size_t N>
-static constexpr size_t arraySize(T(&)[N])
-{
- return N;
-}
-
-} // namespace utils {
-
-#endif // __STOUT_UTILS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
deleted file mode 100644
index e3cf21f..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
+++ /dev/null
@@ -1,107 +0,0 @@
-// 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_UUID_HPP__
-#define __STOUT_UUID_HPP__
-
-#include <assert.h>
-
-#include <sstream>
-#include <string>
-
-#include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
-#include <boost/uuid/uuid_io.hpp>
-
-#include <stout/thread_local.hpp>
-
-#ifdef __WINDOWS__
-#include <stout/windows.hpp>
-#endif // __WINDOWS__
-
-// NOTE: This namespace is necessary because the standard Windows headers
-// define a UUID struct in the global namespace for the DCE RPC API. We put
-// this in the `id::` namespace to avoid collisions. Note also that we include
-// a line below, `using id::UUID`, which allows us to avoid being forced to
-// change most of the callsites that use `UUID` to use `id::UUID` instead.
-namespace id {
-
-struct UUID : boost::uuids::uuid
-{
-public:
- static UUID random()
- {
- static THREAD_LOCAL boost::uuids::random_generator* generator = NULL;
-
- if (generator == NULL) {
- generator = new boost::uuids::random_generator();
- }
-
- return UUID((*generator)());
- }
-
- static UUID fromBytes(const std::string& s)
- {
- boost::uuids::uuid uuid;
- memcpy(&uuid, s.data(), s.size());
- return UUID(uuid);
- }
-
- static UUID fromString(const std::string& s)
- {
- boost::uuids::uuid uuid;
- std::istringstream in(s);
- in >> uuid;
- return UUID(uuid);
- }
-
- std::string toBytes() const
- {
- assert(sizeof(data) == size());
- return std::string(reinterpret_cast<const char*>(data), sizeof(data));
- }
-
- std::string toString() const
- {
- std::ostringstream out;
- out << *this;
- return out.str();
- }
-
-private:
- explicit UUID(const boost::uuids::uuid& uuid)
- : boost::uuids::uuid(uuid) {}
-};
-
-} // namespace id {
-
-// NOTE: see comment for the line `namespace id {`, near the top of the file.
-using id::UUID;
-
-namespace std {
-
-template <>
-struct hash<UUID>
-{
- typedef size_t result_type;
-
- typedef UUID argument_type;
-
- result_type operator()(const argument_type& uuid) const
- {
- return boost::uuids::hash_value(uuid);
- }
-};
-
-} // namespace std {
-
-#endif // __STOUT_UUID_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/version.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/version.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/version.hpp
deleted file mode 100644
index 5ae1c73..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/version.hpp
+++ /dev/null
@@ -1,137 +0,0 @@
-// 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_VERSION_HPP__
-#define __STOUT_VERSION_HPP__
-
-#include <ostream>
-#include <string>
-#include <vector>
-
-#include <stout/error.hpp>
-#include <stout/numify.hpp>
-#include <stout/stringify.hpp>
-#include <stout/strings.hpp>
-#include <stout/try.hpp>
-
-// This class provides convenience routines for version checks.
-//
-// Ideally, the components would be called simply major, minor and
-// patch. However, GNU libstdc++ already defines these as macros for
-// compatibility reasons (man 3 makedev for more information) implicitly
-// included in every compilation.
-//
-// TODO(karya): Consider adding support for more than 3 components, and
-// compatibility operators.
-// TODO(karya): Add support for labels and build metadata. Consider
-// semantic versioning (http://semvar.org/) for specs.
-struct Version
-{
- // Expect the string in the following format:
- // <major>[.<minor>[.<patch>]]
- // Missing components are treated as zero.
- static Try<Version> parse(const std::string& s)
- {
- const size_t maxComponents = 3;
-
- // Use only the part before '-', i.e. strip and discard the tags
- // and labels.
- // TODO(karya): Once we have support for labels and tags, we
- // should not discard the remaining string.
- std::vector<std::string> split =
- strings::split(strings::split(s, "-")[0], ".");
-
- if (split.size() > maxComponents) {
- return Error("Version string has " + stringify(split.size()) +
- " components; maximum " + stringify(maxComponents) +
- " components allowed");
- }
-
- int components[maxComponents] = {0};
-
- for (size_t i = 0; i < split.size(); i++) {
- Try<int> result = numify<int>(split[i]);
- if (result.isError()) {
- return Error("Invalid version component '" + split[i] + "': " +
- result.error());
- }
- components[i] = result.get();
- }
-
- return Version(components[0], components[1], components[2]);
- }
-
- Version(int _majorVersion, int _minorVersion, int _patchVersion)
- : majorVersion(_majorVersion),
- minorVersion(_minorVersion),
- patchVersion(_patchVersion) {}
-
- bool operator==(const Version& other) const
- {
- return majorVersion == other.majorVersion &&
- minorVersion == other.minorVersion &&
- patchVersion == other.patchVersion;
- }
-
- bool operator!=(const Version& other) const
- {
- return !(*this == other);
- }
-
- bool operator<(const Version& other) const
- {
- // Lexicographic ordering.
- if (majorVersion != other.majorVersion) {
- return majorVersion < other.majorVersion;
- } else if (minorVersion != other.minorVersion) {
- return minorVersion < other.minorVersion;
- } else {
- return patchVersion < other.patchVersion;
- }
- }
-
- bool operator>(const Version& other) const
- {
- // Lexicographic ordering.
- if (majorVersion != other.majorVersion) {
- return majorVersion > other.majorVersion;
- } else if (minorVersion != other.minorVersion) {
- return minorVersion > other.minorVersion;
- } else {
- return patchVersion > other.patchVersion;
- }
- }
-
- bool operator<=(const Version& other) const
- {
- return *this < other || *this == other;
- }
-
- bool operator>=(const Version& other) const
- {
- return *this > other || *this == other;
- }
-
- friend inline std::ostream& operator<<(std::ostream& s, const Version& v);
-
- const int majorVersion;
- const int minorVersion;
- const int patchVersion;
-};
-
-
-inline std::ostream& operator<<(std::ostream& s, const Version& v)
-{
- return s << v.majorVersion << "." << v.minorVersion << "." << v.patchVersion;
-}
-
-#endif // __STOUT_VERSION_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
deleted file mode 100644
index a7a59e7..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
+++ /dev/null
@@ -1,422 +0,0 @@
-// 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_WINDOWS_HPP__
-#define __STOUT_WINDOWS_HPP__
-
-
-#include <direct.h> // For `_mkdir`.
-#include <fcntl.h> // For file access flags like `_O_CREAT`.
-#include <io.h> // For `_read`, `_write`.
-#include <stdlib.h> // For `_PATH_MAX`.
-
-#include <sys/stat.h> // For permissions flags.
-
-#include <BaseTsd.h> // For `SSIZE_T`.
-// We include `Winsock2.h` before `Windows.h` explicitly to avoid symbold
-// re-definitions. This is a known pattern in the windows community.
-#include <WS2tcpip.h>
-#include <Winsock2.h>
-#include <mswsock.h>
-#include <Windows.h>
-
-#include <memory>
-
-
-#ifdef _UNICODE
-// Much of the core Windows API is available both in `string` and `wstring`
-// varieties. To avoid polluting the namespace with two versions of every
-// function, a common pattern in the Windows headers is to offer a single macro
-// that expands to the `string` or `wstring` version, depending on whether the
-// `_UNICODE` preprocessor symbol is set. For example, `GetMessage` will expand
-// to either `GetMessageA` (the `string` version) or `GetMessageW` (the
-// `wstring` version) depending on whether this symbol is defined.
-//
-// The downside of this is that it makes POSIX interop really hard. Hence, we
-// refuse to compile if such a symbol is passed in during compilation.
-#error "Mesos doesn't currently support the `_UNICODE` Windows header constant"
-#endif // _UNICODE
-
-// An RAII `HANDLE`.
-class SharedHandle : public std::shared_ptr<void>
-{
- static_assert(std::is_same<HANDLE, void*>::value,
- "Expected `HANDLE` to be of type `void*`.");
-
-public:
- template <typename Deleter>
- SharedHandle(HANDLE handle, Deleter deleter)
- : std::shared_ptr<void>(handle, deleter) {}
-
- HANDLE get_handle() const { return this->get(); }
-};
-
-
-// Definitions and constants used for Windows compat.
-//
-// Gathers most of the Windows-compatibility definitions. This makes it
-// possible for files throughout the codebase to remain relatively free of all
-// the #if's we'd need to make them work.
-//
-// Roughly, the things that should go in this file are definitions and
-// declarations that one would not mind being:
-// * in global scope.
-// * globally available throughout both the Stout codebase, and any code
-// that uses it (such as Mesos).
-
-
-// This code un-defines the global `GetMessage` macro defined by the Windows
-// headers, and replaces it with an inline function that is equivalent.
-//
-// There are two reasons for doing this. The first is because this macro
-// interferes with `google::protobufs::Reflection::GetMessage`. Replacing the
-// `GetMessage` macro with an inline function allows people calling the
-// `GetMessage` macro to carry on doing so with no code changes, but it will
-// also allow us to use `google::protobufs::Reflection::GetMessage` without
-// interference from the macro.
-//
-// The second is because we don't want to obliterate the `GetMessage` macro for
-// people who include this header, either on purpose, or incidentally as part
-// of some other Mesos header. The effect is that our need to call protobuf's
-// `GetMessage` function has no deleterious effect on customers of this API.
-//
-// NOTE: the Windows headers also don't use define-once semantics for the
-// `GetMessage` macro. In particular, this means that every time you include
-// `Winuser.h` and a `GetMessage` macro isn't defined, the Windows headers will
-// redefine it for you. The impact of this is that you should re-un-define the
-// macro every time you include `Windows.h`; since we should be including
-// `Windows.h` only from this file, we un-define it just after we include
-// `Windows.h`.
-#ifdef GetMessage
-inline BOOL GetMessageWindows(
- LPMSG lpMsg,
- HWND hWnd,
- UINT wMsgFilterMin,
- UINT wMsgFilterMax)
-{
- return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
-}
-#undef GetMessage
-inline BOOL GetMessage(
- LPMSG lpMsg,
- HWND hWnd,
- UINT wMsgFilterMin,
- UINT wMsgFilterMax)
-{
- return GetMessageWindows(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
-}
-#endif // GetMessage
-
-
-// Zookeeper's native `winconfig.h` defines a macro `random` to point at
-// `rand`. This inteferes with `UUID::rand`, so we redfine it as a global
-// function in a manner similar to the `GetMessage` macro above. See the
-// accompanying comment for rationale.
-#ifdef random
-#undef random
-inline int random()
-{
- return rand();
-}
-#endif // random
-
-
-// Define constants used for Windows compat. Allows a lot of code on
-// Windows and POSIX systems to be the same, because we can pass the
-// same constants to functions we call to do things like file I/O.
-#define STDIN_FILENO 0
-#define STDOUT_FILENO 1
-#define STDERR_FILENO 2
-
-#define R_OK 0x4
-#define W_OK 0x2
-#define X_OK 0x0 // No such permission on Windows.
-#define F_OK 0x0
-
-#define O_RDONLY _O_RDONLY
-#define O_WRONLY _O_WRONLY
-#define O_RDWR _O_RDWR
-#define O_CREAT _O_CREAT
-#define O_TRUNC _O_TRUNC
-#define O_APPEND _O_APPEND
-#define O_CLOEXEC _O_NOINHERIT
-
-// TODO(hausdorff): (MESOS-3398) Not defined on Windows. This value is
-// temporary.
-#define MAXHOSTNAMELEN 64
-
-#define PATH_MAX _MAX_PATH
-
-// NOTE: for details on what this value should be, consult [1], [2], and [3].
-//
-// [1] http://www.opensource.apple.com/source/gnumake/gnumake-119/make/w32/include/dirent.h
-// [2] https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
-// [3] https://msdn.microsoft.com/en-us/library/930f87yf.aspx
-const int NAME_MAX = PATH_MAX;
-
-// Corresponds to `mode_t` defined in sys/types.h of the POSIX spec.
-// See large "permissions API" comment below for an explanation of
-// why this is an int instead of unsigned short (as is common on
-// POSIX).
-typedef int mode_t;
-
-// `DWORD` is expected to be the type holding PIDs throughout the Windows API,
-// including functions like `OpenProcess`.
-typedef DWORD pid_t;
-
-typedef int uid_t;
-typedef int gid_t;
-
-typedef SSIZE_T ssize_t;
-
-// Socket flags. Define behavior of a socket when it (e.g.) shuts down. We map
-// the Windows versions of these flags to their POSIX equivalents so we don't
-// have to change any socket code.
-constexpr int SHUT_RD = SD_RECEIVE;
-constexpr int MSG_NOSIGNAL = 0; // `SIGPIPE` signal does not exist on Windows.
-
-// The following functions are usually macros on POSIX; we provide them here as
-// functions to avoid having global macros lying around. Note that these
-// operate on the `_stat` struct (a Windows version of the standard POSIX
-// `stat` struct), of which the `st_mode` field is known to be an `int`.
-inline bool S_ISDIR(const int mode)
-{
- return (mode & S_IFMT) == S_IFDIR; // Directory.
-}
-
-inline bool S_ISREG(const int mode)
-{
- return (mode & S_IFMT) == S_IFREG; // File.
-}
-
-inline bool S_ISCHR(const int mode)
-{
- return (mode & S_IFMT) == S_IFCHR; // Character device.
-}
-
-inline bool S_ISFIFO(const int mode)
-{
- return (mode & S_IFMT) == _S_IFIFO; // Pipe.
-}
-
-inline bool S_ISBLK(const int mode)
-{
- return false; // Block special device.
-}
-
-inline bool S_ISSOCK(const int mode)
-{
- return false; // Socket.
-}
-
-inline bool S_ISLNK(const int mode)
-{
- return false; // Symbolic link.
-}
-
-// Permissions API. (cf. MESOS-3176 to track ongoing permissions work.)
-//
-// We are currently able to emulate a subset of the POSIX permissions model
-// with the Windows model:
-// [x] User write permissions.
-// [x] User read permissions.
-// [ ] User execute permissions.
-// [ ] Group permissions of any sort.
-// [ ] Other permissions of any sort.
-// [x] Flags to control "fallback" behavior (e.g., we might choose
-// to fall back to user readability when the user passes the
-// group readability flag in, since we currently do not support
-// group readability).
-//
-//
-// Rationale:
-// Windows currently implements two permissions models: (1) an extremely
-// primitive permission model it largely inherited from DOS, and (2) the Access
-// Control List (ACL) API. Because there is no trivial way to map the classic
-// POSIX model into the ACL model, we have implemented POSIX-style permissions
-// in terms of the DOS model. The result is the permissions limitations above.
-//
-//
-// Flag implementation:
-// Flags fall into the following two categories.
-// (1) Flags which exist in both permission models, but which have
-// different names (e.g., `S_IRUSR` in POSIX is called `_S_IREAD` on
-// Windows). In this case, we define the POSIX name to be the Windows
-// value (e.g., we define `S_IRUSR` to have the same value as `_S_IREAD`),
-// so that we can pass the POSIX name into Windows functions like
-// `_open`.
-// (2) Flags which exist only on POSIX (e.g., `S_IXUSR`). Here we
-// define the POSIX name to be the value given in the glibc
-// documentation[1], shifted left by 16 bits (since `mode_t`
-// is unsigned short on POSIX and `int` on Windows). We give these
-// flags glibc values to stay consistent, and so that existing
-// calls to functions like `open` do not break when they try to
-// use a flag that doesn't exist on Windows. But, of course,
-// these flags do not affect the execution of these functions.
-//
-//
-// Flag strictness:
-// Because the current implementation does not directly support setting or
-// getting group or other permission bits on the Windows platform, there is a
-// question of what we should fall back to when these flags are passed in to
-// Stout methods.
-//
-// TODO(hausdorff): Investigate permissions mappings.
-// We force "strictness" of the permission flag semantics:
-// * The group permissions flags will not fall back to anything, and will be
-// completely ignored.
-// * Other permissions: Same as above, but with other permissions.
-//
-//
-// Execute permissions:
-// Because DOS has no notion of "execute permissions", we define execute
-// permissions to be read permissions. This is not ideal, but it is closest to
-// being accurate.
-//
-//
-// [1] http://www.delorie.com/gnu/docs/glibc/libc_288.html
-
-
-// User permission flags.
-const mode_t S_IRUSR = mode_t(_S_IREAD); // Readable by user.
-const mode_t S_IWUSR = mode_t(_S_IWRITE); // Writeable by user.
-const mode_t S_IXUSR = S_IRUSR; // Fallback to user read.
-const mode_t S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR;
-
-
-// Group permission flags. Lossy mapping to Windows permissions. See
-// note above about flag strictness for explanation.
-const mode_t S_IRGRP = 0x00200000; // No-op.
-const mode_t S_IWGRP = 0x00100000; // No-op.
-const mode_t S_IXGRP = 0x00080000; // No-op.
-const mode_t S_IRWXG = S_IRGRP | S_IWGRP | S_IXGRP;
-
-
-// Other permission flags. Lossy mapping to Windows permissions. See
-// note above about flag stictness for explanation.
-const mode_t S_IROTH = 0x00040000; // No-op.
-const mode_t S_IWOTH = 0x00020000; // No-op.
-const mode_t S_IXOTH = 0x00010000; // No-op.
-const mode_t S_IRWXO = S_IROTH | S_IWOTH | S_IXOTH;
-
-
-// Flags for set-ID-on-exec.
-const mode_t S_ISUID = 0x08000000; // No-op.
-const mode_t S_ISGID = 0x04000000; // No-op.
-const mode_t S_ISVTX = 0x02000000; // No-op.
-
-
-// Flags not supported by Windows.
-const mode_t O_SYNC = 0x00000000; // No-op.
-
-
-inline auto strerror_r(int errnum, char* buffer, size_t length) ->
-decltype(strerror_s(buffer, length, errnum))
-{
- return strerror_s(buffer, length, errnum);
-}
-
-
-// File I/O function aliases.
-//
-// NOTE: The use of `auto` and the trailing return type in the following
-// functions are meant to make it easier for Linux developers to use and
-// maintain the code. It is an explicit marker that we are using the compiler
-// to guarantee that the return type is identical to whatever is in the Windows
-// implementation of the standard.
-inline auto write(int fd, const void* buffer, size_t count) ->
-decltype(_write(fd, buffer, count))
-{
- return _write(fd, buffer, count);
-}
-
-
-
-inline auto chdir(const char* path) ->
-decltype(_chdir(path))
-{
- return _chdir(path);
-}
-
-
-inline auto getcwd(char* path, int maxlen) ->
-decltype(_getcwd(path, maxlen))
-{
- return _getcwd(path, maxlen);
-}
-
-
-inline auto mkdir(const char* path, mode_t mode) ->
-decltype(_mkdir(path))
-{
- return _mkdir(path);
-}
-
-
-inline auto mktemp(char* path) ->
-decltype(_mktemp(path))
-{
- return _mktemp(path);
-}
-
-
-inline auto mkstemp(char* path) ->
-decltype(_mktemp_s(path, strlen(path) + 1))
-{
- // NOTE: in the POSIX spec, `mkstemp` will generate a random filename from
- // the `path` template, `open` that filename, and return the resulting file
- // descriptor. On Windows, `_mktemp_s` will actually only generate the path,
- // so here we actually have to call `open` ourselves to get a file descriptor
- // we can return as a result.
- if (_mktemp_s(path, strlen(path) + 1) != 0) {
- return -1;
- }
-
- // NOTE: We open the file with read / write access for the given user, an
- // attempt to match POSIX's specification of `mkstemp`.
- return _open(path, S_IRUSR | S_IWUSR);
-}
-
-
-inline auto realpath(const char* path, char* resolved) ->
-decltype(_fullpath(resolved, path, PATH_MAX))
-{
- return _fullpath(resolved, path, PATH_MAX);
-}
-
-
-inline auto access(const char* fileName, int accessMode) ->
-decltype(_access(fileName, accessMode))
-{
- return _access(fileName, accessMode);
-}
-
-// `os::system` returns -1 if the processor cannot be started
-// therefore any return value indicates the process has been started
-#ifndef WIFEXITED
-#define WIFEXITED(x) ((x) != -1)
-#endif // WIFWXITED
-
-// Returns the exit status of the child.
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(x) (x & 0xFF)
-#endif // WEXITSTATUS
-
-#define SIGPIPE 100
-
-// Specifies that `::waitpid` should return immediately rather than blocking
-// and waiting for child to notify of state change.
-#ifndef WNOHANG
-#define WNOHANG 1
-#endif // WNOHANG
-
-#endif // __STOUT_WINDOWS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/windows/dynamiclibrary.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/dynamiclibrary.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/dynamiclibrary.hpp
deleted file mode 100644
index 4235cb1..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/dynamiclibrary.hpp
+++ /dev/null
@@ -1,98 +0,0 @@
-// 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_WINDOWS_DYNAMICLIBRARY_HPP__
-#define __STOUT_WINDOWS_DYNAMICLIBRARY_HPP__
-
-#include <string>
-
-#include <stout/nothing.hpp>
-#include <stout/option.hpp>
-#include <stout/try.hpp>
-
-#include <stout/windows/error.hpp>
-
-/**
- * DynamicLibrary is a very simple wrapper around the programming interface
- * to the dynamic linking loader.
- */
-class DynamicLibrary
-{
-public:
- DynamicLibrary() : handle_(NULL) { }
-
- virtual ~DynamicLibrary()
- {
- if (handle_ != NULL) {
- close();
- }
- }
-
- Try<Nothing> open(const std::string& path)
- {
- // Check if we've already opened a library.
- if (handle_ != NULL) {
- return Error("Library already opened");
- }
-
- handle_ = LoadLibrary(path.c_str());
-
- if (handle_ == NULL) {
- return WindowsError("Could not load library '" + path + "'");
- }
-
- path_ = path;
-
- return Nothing();
- }
-
- Try<Nothing> close()
- {
- if (handle_ == NULL) {
- return Error("Could not close library; handle was already `NULL`");
- }
-
- if (!FreeLibrary(handle_)) {
- return WindowsError(
- "Could not close library '" + (path_.isSome() ? path_.get() : ""));
- }
-
- handle_ = NULL;
- path_ = None();
-
- return Nothing();
- }
-
- Try<void*> loadSymbol(const std::string& name)
- {
- if (handle_ == NULL) {
- return Error(
- "Could not get symbol '" + name + "'; library handle was `NULL`");
- }
-
- void* symbol = GetProcAddress(handle_, name.c_str());
-
- if (symbol == NULL) {
- return WindowsError(
- "Error looking up symbol '" + name + "' in '" +
- (path_.isSome() ? path_.get() : ""));
- }
-
- return symbol;
- }
-
-private:
- HMODULE handle_;
- Option<std::string> path_;
-};
-
-#endif // __STOUT_WINDOWS_DYNAMICLIBRARY_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
deleted file mode 100644
index d634491..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/error.hpp
+++ /dev/null
@@ -1,121 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you 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_WINDOWS_ERROR_HPP__
-#define __STOUT_WINDOWS_ERROR_HPP__
-
-#include <stout/error.hpp>
-#include <stout/windows.hpp>
-
-
-// A useful type that can be used to represent a Try that has failed. This is a
-// lot like `ErrnoError`, except instead of wrapping an error coming from the C
-// standard libraries, it wraps an error coming from the Windows APIs.
-class WindowsErrorBase : public Error
-{
-public:
- WindowsErrorBase(DWORD _code)
- : Error(get_last_error_as_string(_code)), code(_code) {}
-
- WindowsErrorBase(DWORD _code, const std::string& message)
- : Error(message + ": " + get_last_error_as_string(_code)), code(_code) {}
-
- const DWORD code;
-
-private:
- static std::string get_last_error_as_string(DWORD errorCode)
- {
- // Default if no error.
- if (errorCode == 0) {
- return std::string();
- }
-
- DWORD allocate_message_buffer =
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS;
-
- DWORD default_language = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
-
- // This following function `FormatMessage` is a lot like `strerror`, except
- // it pretty-prints errors from the Windows API instead of from the C
- // standard library. Basically, the semantics are: we pass in `errorCode`,
- // and it allocates room for a pretty-printed error message at
- // `message_buffer`, and then dumps said pretty-printed error message at
- // that address, in our `default_language`.
- //
- // The 5th actual parameter (namely `(LPSTR)&message_buffer`), may look
- // strange to readers of this code. It is copied directly out of the
- // documentation[1], and is unfortunately required to get the
- // pretty-printed error message. The short story is:
- //
- // * The flag `FORMAT_MESSAGE_ALLOCATE_BUFFER` tells `FormatMessage` to
- // point `message_buffer` (which is an `LPSTR` a.k.a. `char*`) at a
- // string error message. But, `message_buffer` to point a `char*` at a
- // different place, `FormatMessage` would need the address
- // `&message_buffer` so that it could change where it is pointing.
- // * So, to solve this problem, the API writers decided that when you
- // pass that flag in, `FormatMessage` will treat the 5th parameter not
- // as `LPSTR` (which is what the type is in the function signagure),
- // but as `LPSTR*` a.k.a. `char**`, which (assuming you've casted the
- // parameter correctly) allows it to allocate the message on your
- // behalf, and change `message_buffer` to point at this new error
- // string.
- // * This is why we need this strange cast that you see below.
- //
- // Finally, and this is important: it is up to the user to free the memory
- // with `LocalFree`! The line below where we do this comes directly from
- // the documentation as well.
- //
- // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx
- LPSTR message_buffer;
- size_t size = FormatMessage(
- allocate_message_buffer,
- NULL, // Ignored.
- errorCode,
- default_language,
- (LPSTR) &message_buffer, // See comment above about quirky cast.
- 0, // Ignored.
- NULL); // Ignored.
-
- std::string message(message_buffer, size);
-
- // Required per documentation above.
- LocalFree(message_buffer);
-
- return message;
- }
-};
-
-
-class WindowsError : public WindowsErrorBase {
-public:
- WindowsError() : WindowsErrorBase(::GetLastError()) {}
-
- WindowsError(const std::string& message)
- : WindowsErrorBase(::GetLastError(), message) {}
-};
-
-
-class WindowsSocketError : public WindowsErrorBase {
-public:
- WindowsSocketError() : WindowsErrorBase(::WSAGetLastError()) {}
-
- WindowsSocketError(const std::string& message)
- : WindowsErrorBase(::WSAGetLastError(), message) {}
-};
-
-#endif // __STOUT_WINDOWS_ERROR_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/windows/format.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/format.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/format.hpp
deleted file mode 100644
index 872ddbc..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/format.hpp
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2015 Mesosphere, Inc.
-//
-// This file has been modified from its original form by Mesosphere, Inc.
-// All modifications made to this file by Mesosphere (the "Modifications")
-// are copyright 2015 Mesosphere, Inc.
-//
-// 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.
-//
-// ---
-//
-// The original file on which the Modifications have been made were
-// provided to Mesosphere pursuant to the following terms:
-//
-// Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/,
-// http://asprintf.insanecoding.org/)
-//
-// Permission to use, copy, modify, and distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef __STOUT_WINDOWS_FORMAT_HPP__
-#define __STOUT_WINDOWS_FORMAT_HPP__
-
-#include <stdio.h> // For '_vscprintf', 'vsnprintf'.
-#include <stdlib.h> // For 'malloc', 'free'.
-#include <limits.h> // For 'INT_MAX'.
-
-
-inline int vasprintf(char** buffer, const char* format, va_list args)
-{
- int result = -1;
- int size = _vscprintf(format, args) + 1;
-
- if (size >= 0 && size < INT_MAX) {
- *buffer = (char*) malloc(size);
-
- if (*buffer) {
- result = vsnprintf(*buffer, size, format, args);
-
- if (result < 0) {
- free(*buffer);
- }
- }
- }
-
- return result;
-}
-
-
-#endif // __STOUT_WINDOWS_FORMAT_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
deleted file mode 100644
index 99887b1..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
+++ /dev/null
@@ -1,133 +0,0 @@
-// 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_WINDOWS_FS_HPP__
-#define __STOUT_WINDOWS_FS_HPP__
-
-#include <string>
-
-#include <stout/bytes.hpp>
-#include <stout/error.hpp>
-#include <stout/nothing.hpp>
-#include <stout/try.hpp>
-
-#include <stout/internal/windows/symlink.hpp>
-
-namespace fs {
-
-// Returns the total disk size in bytes.
-inline Try<Bytes> size(const std::string& path = "/")
-{
- Result<std::string> real_path = os::realpath(path);
- if (!real_path.isSome()) {
- return Error(
- "Failed to get realpath for '" + path+ "': " +
- (real_path.isError() ? real_path.error() : "No such directory"));
- }
-
- ULARGE_INTEGER free_bytes, total_bytes, total_free_bytes;
- if (::GetDiskFreeSpaceEx(
- real_path.get().c_str(),
- &free_bytes,
- &total_bytes,
- &total_free_bytes) == 0) {
- return WindowsError(
- "Error invoking 'GetDiskFreeSpaceEx' on '" + path + "'");
- }
-
- return Bytes(total_bytes.QuadPart);
-}
-
-
-// Returns relative disk usage of the file system that the given path
-// is mounted at.
-inline Try<double> usage(const std::string& path = "/")
-{
- Result<std::string> real_path = os::realpath(path);
- if (!real_path.isSome()) {
- return Error(
- "Failed to get realpath for '" + path + "': " +
- (real_path.isError() ? real_path.error() : "No such directory"));
- }
-
- ULARGE_INTEGER free_bytes, total_bytes, total_free_bytes;
- if (::GetDiskFreeSpaceEx(
- real_path.get().c_str(),
- &free_bytes,
- &total_bytes,
- &total_free_bytes) == 0) {
- return WindowsError(
- "Error invoking 'GetDiskFreeSpaceEx' on '" + path + "'");
- }
-
- double used = total_bytes.QuadPart - free_bytes.QuadPart;
- return used / total_bytes.QuadPart;
-}
-
-
-inline Try<Nothing> symlink(
- const std::string& original,
- const std::string& link)
-{
- return internal::windows::create_symbolic_link(original, link);
-}
-
-
-// Returns a list of all files matching the given pattern. This is meant to
-// be a lightweight alternative to glob() - the only supported wildcards are
-// `?` and `*`, and only when they appear at the tail end of `pattern` (e.g.
-// `/root/dir/subdir/*.txt` or `/root/dir/subdir/file?.txt`.
-inline Try<std::list<std::string>> list(const std::string& pattern)
-{
- std::list<std::string> found_files;
- WIN32_FIND_DATA find_data;
- const HANDLE search_handle = ::FindFirstFile(pattern.c_str(), &find_data);
-
- if (search_handle == INVALID_HANDLE_VALUE) {
- // For compliance with the POSIX implementation (which uses `::glob`),
- // return an empty list instead of an error when the path does not exist.
- int error = ::GetLastError();
- if (error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND) {
- return found_files;
- }
-
- return WindowsError(
- "'fs::list' failed when searching for files with pattern '" +
- pattern + "'");
- }
-
- do {
- const std::string current_file(find_data.cFileName);
-
- // Ignore `.` and `..` entries
- if (current_file.compare(".") != 0 && current_file.compare("..") != 0) {
- found_files.push_back(current_file);
- }
- } while (::FindNextFile(search_handle, &find_data));
-
- // Cache `FindNextFile` error, `FindClose` will overwrite it
- const DWORD error = ::GetLastError();
- ::FindClose(search_handle);
-
- if (error != ERROR_NO_MORE_FILES) {
- ::SetLastError(error);
- return WindowsError(
- "'fs::list': 'FindNextFile' failed when searching for files with "
- "'pattern '" + pattern + "'");
- }
-
- return found_files;
-}
-
-} // namespace fs {
-
-#endif // __STOUT_WINDOWS_FS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/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
deleted file mode 100644
index 261768e..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
+++ /dev/null
@@ -1,672 +0,0 @@
-// 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_WINDOWS_OS_HPP__
-#define __STOUT_WINDOWS_OS_HPP__
-
-#include <direct.h>
-#include <io.h>
-#include <TlHelp32.h>
-#include <Psapi.h>
-
-#include <sys/utime.h>
-
-#include <list>
-#include <map>
-#include <set>
-#include <string>
-
-#include <stout/duration.hpp>
-#include <stout/none.hpp>
-#include <stout/nothing.hpp>
-#include <stout/option.hpp>
-#include <stout/path.hpp>
-#include <stout/try.hpp>
-#include <stout/windows.hpp>
-
-#include <stout/os/os.hpp>
-#include <stout/os/read.hpp>
-
-#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.
-// NOTE: Windows does not have the concept of a process group, so we need to
-// enumerate all processes.
-inline Try<std::set<pid_t>> pids(Option<pid_t> group, Option<pid_t> session)
-{
- DWORD max_items = 4096;
- DWORD bytes_returned;
- std::vector<pid_t> processes;
- size_t size_in_bytes;
-
- // Attempt to populate `processes` with PIDs. We repeatedly call
- // `EnumProcesses` with increasingly large arrays until it "succeeds" at
- // populating the array with PIDs. The criteria for determining when
- // `EnumProcesses` has succeeded are:
- // (1) the return value is nonzero.
- // (2) the `bytes_returned` is less than the number of bytes in the array.
- do {
- // TODO(alexnaparu): Set a limit to the memory that can be used.
- processes.resize(max_items);
- size_in_bytes = processes.size() * sizeof(pid_t);
- BOOL result = ::EnumProcesses(processes.data(), size_in_bytes,
- &bytes_returned);
-
- if (!result) {
- return WindowsError("os::pids: Call to `EnumProcesses` failed");
- }
-
- max_items *= 2;
- } while (bytes_returned >= size_in_bytes);
-
- return std::set<pid_t>(processes.begin(), processes.end());
-}
-
-
-inline Try<std::set<pid_t>> pids()
-{
- return pids(None(), None());
-}
-
-
-// Sets the value associated with the specified key in the set of
-// environment variables.
-inline void setenv(
- const std::string& key,
- const std::string& value,
- bool overwrite = true)
-{
- // Do not set the variable if already set and `overwrite` was not specified.
- //
- // Per MSDN[1], `GetEnvironmentVariable` returns 0 on error and sets the
- // error code to `ERROR_ENVVAR_NOT_FOUND` if the variable was not found.
- //
- // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx
- if (!overwrite &&
- ::GetEnvironmentVariable(key.c_str(), NULL, 0) != 0 &&
- ::GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
- return;
- }
-
- // `SetEnvironmentVariable` returns an error code, but we can't act on it.
- ::SetEnvironmentVariable(key.c_str(), value.c_str());
-}
-
-
-// Unsets the value associated with the specified key in the set of
-// environment variables.
-inline void unsetenv(const std::string& key)
-{
- // Per MSDN documentation[1], passing `NULL` as the value will cause
- // `SetEnvironmentVariable` to delete the key from the process's environment.
- ::SetEnvironmentVariable(key.c_str(), NULL);
-}
-
-
-// Suspends execution of the calling process until a child specified by `pid`
-// has changed state. Unlike the POSIX standard function `::waitpid`, this
-// function does not use -1 and 0 to signify errors and nonblocking return.
-// Instead, we return `Result<pid_t>`:
-// * In case of error, we return `Error` rather than -1. For example, we
-// would return an `Error` in case of `EINVAL`.
-// * In case of nonblocking return, we return `None` rather than 0. For
-// example, if we pass `WNOHANG` in the `options`, we would expect 0 to be
-// returned in the case that children specified by `pid` exist, but have
-// not changed state yet. In this case we return `None` instead.
-//
-// NOTE: There are important differences between the POSIX and Windows
-// implementations of this function:
-// * On POSIX, `pid_t` is a signed number, but on Windows, PIDs are `DWORD`,
-// which is `unsigned long`. Thus, if we use `DWORD` to represent the `pid`
-// argument, passing -1 as the `pid` would (on most modern servers)
-// silently convert to a really large `pid`. This is undesirable.
-// * Since it is important to be able to detect -1 has been passed to
-// `os::waitpid`, as a matter of practicality, we choose to:
-// (1) Use `long` to represent the `pid` argument.
-// (2) Disable using any value <= 0 for `pid` on Windows.
-// * This decision is pragmatic. The reasoning is:
-// (1) The Windows code paths call `os::waitpid` in only a handful of
-// places, and in none of these conditions do we need `-1` as a value.
-// (2) Since PIDs virtually never take on values outside the range of
-// vanilla signed `long` it is likely that an accidental conversion
-// will never happen.
-// (3) Even though it is not formalized in the C specification, the
-// implementation of `long` on the vast majority of production servers
-// is 2's complement, so we expect that when we accidentally do
-// implicitly convert from `unsigned long` to `long`, we will "wrap
-// around" to negative values. And since we've disabled the negative
-// `pid` in the Windows implementation, we should error out.
-// * Finally, on Windows, we currently do not check that the process we are
-// attempting to await is a child process.
-inline Result<pid_t> waitpid(long pid, int* status, int options)
-{
- const bool wait_for_child = (options & WNOHANG) == 0;
-
- // NOTE: Windows does not implement pids <= 0.
- if (pid <= 0) {
- errno = ENOSYS;
- return ErrnoError(
- "os::waitpid: Value of pid is '" + stringify(pid) +
- "'; the Windows implementation currently does not allow values <= 0");
- } else if (options != 0 && options != WNOHANG) {
- // NOTE: We only support `options == 0` or `options == WNOHANG`. On Windows
- // no flags other than `WNOHANG` are supported.
- errno = ENOSYS;
- return ErrnoError(
- "os::waitpid: Only flag `WNOHANG` is implemented on Windows");
- }
-
- // TODO(hausdorff): Check that `pid` is one of the child processes. If not,
- // set `errno` to `ECHILD` and return -1.
-
- // Open the child process as a safe `SharedHandle`.
- const HANDLE process = ::OpenProcess(
- PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
- FALSE,
- static_cast<DWORD>(pid));
-
- if (process == NULL) {
- return WindowsError("os::waitpid: Failed to open process for pid '" +
- stringify(pid) + "'");
- }
-
- SharedHandle scoped_process(process, ::CloseHandle);
-
- // If `WNOHANG` flag is set, don't wait. Otherwise, wait for child to
- // terminate.
- const DWORD wait_time = wait_for_child ? INFINITE : 0;
- const DWORD wait_results = ::WaitForSingleObject(
- scoped_process.get(),
- wait_time);
-
- // Verify our wait exited correctly.
- const bool state_signaled = wait_results == WAIT_OBJECT_0;
- if (options == 0 && !state_signaled) {
- // If `WNOHANG` is not set, then we should have stopped waiting only for a
- // state change in `scoped_process`.
- errno = ECHILD;
- return WindowsError(
- "os::waitpid: Failed to wait for pid '" + stringify(pid) +
- "'. `::WaitForSingleObject` should have waited for child process to " +
- "exit, but returned code '" + stringify(wait_results) +
- "' instead");
- } else if (wait_for_child && !state_signaled &&
- wait_results != WAIT_TIMEOUT) {
- // If `WNOHANG` is set, then a successful wait should report either a
- // timeout (since we set the time to wait to `0`), or a successful state
- // change of `scoped_process`. Anything else is an error.
- errno = ECHILD;
- return WindowsError(
- "os::waitpid: Failed to wait for pid '" + stringify(pid) +
- "'. `ENOHANG` flag was passed in, so `::WaitForSingleObject` should " +
- "have either returned `WAIT_OBJECT_0` or `WAIT_TIMEOUT` (the " +
- "timeout was set to 0, because we are not waiting for the child), " +
- "but instead returned code '" + stringify(wait_results) + "'");
- }
-
- if (!wait_for_child && wait_results == WAIT_TIMEOUT) {
- // Success. `ENOHANG` was set and we got a timeout, so return `None` (POSIX
- // `::waitpid` would return 0 here).
- return None();
- }
-
- // Attempt to retrieve exit code from child process. Store that exit code in
- // the `status` variable if it's `NULL`.
- DWORD child_exit_code = 0;
- if (!::GetExitCodeProcess(scoped_process.get(), &child_exit_code)) {
- errno = ECHILD;
- return WindowsError(
- "os::waitpid: Successfully waited on child process with pid '" +
- std::to_string(pid) + "', but could not retrieve exit code");
- }
-
- if (status != NULL) {
- *status = child_exit_code;
- }
-
- // Success. Return pid of the child process for which the status is reported.
- return pid;
-}
-
-
-inline std::string hstrerror(int err)
-{
- char buffer[1024];
- DWORD format_error = 0;
-
- // NOTE: Per the Linux documentation[1], `h_errno` can have only one of the
- // following errors.
- switch (err) {
- case WSAHOST_NOT_FOUND:
- case WSANO_DATA:
- case WSANO_RECOVERY:
- case WSATRY_AGAIN: {
- format_error = ::FormatMessage(
- FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- buffer,
- sizeof(buffer),
- NULL);
- break;
- }
- default: {
- return "Unknown resolver error";
- }
- }
-
- if (format_error == 0) {
- // If call to `FormatMessage` fails, then we choose to output the error
- // code rather than call `FormatMessage` again.
- return "os::hstrerror: Call to `FormatMessage` failed with error code" +
- std::to_string(GetLastError());
- } else {
- return buffer;
- }
-}
-
-
-// This function is a portable version of execvpe ('p' means searching
-// executable from PATH and 'e' means setting environments). We add
-// this function because it is not available on all systems.
-inline int execvpe(const char* file, char** argv, char** envp) = delete;
-
-
-inline Try<Nothing> chown(
- uid_t uid,
- gid_t gid,
- const std::string& path,
- bool recursive) = delete;
-
-
-inline Try<Nothing> chmod(const std::string& path, int mode) = delete;
-
-
-inline Try<Nothing> mknod(
- const std::string& path,
- mode_t mode,
- dev_t dev) = delete;
-
-
-// Suspends execution for the given duration.
-// NOTE: This implementation features a millisecond-resolution sleep API, while
-// the POSIX version uses a nanosecond-resolution sleep API. As of this writing,
-// Mesos only requires millisecond resolution, so this is ok for now.
-inline Try<Nothing> sleep(const Duration& duration)
-{
- ::Sleep(static_cast<DWORD>(duration.ms()));
-
- return Nothing();
-}
-
-
-// Returns the list of files that match the given (shell) pattern.
-// NOTE: Deleted on Windows, as a POSIX-API-compliant `glob` is much more
-// trouble than its worth, considering our relatively simple usage.
-inline Try<std::list<std::string>> glob(const std::string& pattern) = delete;
-
-
-// Returns the total number of cpus (cores).
-inline Try<long> cpus()
-{
- SYSTEM_INFO sysInfo;
- ::GetSystemInfo(&sysInfo);
- return static_cast<long>(sysInfo.dwNumberOfProcessors);
-}
-
-// Returns load struct with average system loads for the last
-// 1, 5 and 15 minutes respectively.
-// Load values should be interpreted as usual average loads from
-// uptime(1).
-inline Try<Load> loadavg()
-{
- // No Windows equivalent, return an error until there is a need. We can
- // construct an approximation of this function by periodically polling
- // `GetSystemTimes` and using a sliding window of statistics.
- return WindowsErrorBase(ERROR_NOT_SUPPORTED,
- "Failed to determine system load averages");
-}
-
-
-// Returns the total size of main and free memory.
-inline Try<Memory> memory()
-{
- Memory memory;
-
- MEMORYSTATUSEX memory_status;
- memory_status.dwLength = sizeof(MEMORYSTATUSEX);
- if (!::GlobalMemoryStatusEx(&memory_status)) {
- return WindowsError("os::memory: Call to `GlobalMemoryStatusEx` failed");
- }
-
- memory.total = Bytes(memory_status.ullTotalPhys);
- memory.free = Bytes(memory_status.ullAvailPhys);
- memory.totalSwap = Bytes(memory_status.ullTotalPageFile);
- memory.freeSwap = Bytes(memory_status.ullAvailPageFile);
-
- return 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()
-{
- 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
-// returns a string representation of its value. If no environment
-// variable matching key is found, None() is returned.
-inline Option<std::string> getenv(const std::string& key)
-{
- DWORD buffer_size = ::GetEnvironmentVariable(key.c_str(), NULL, 0);
- if (buffer_size == 0) {
- return None();
- }
-
- std::unique_ptr<char> environment(new char[buffer_size]);
-
- DWORD value_size =
- ::GetEnvironmentVariable(key.c_str(), environment.get(), buffer_size);
-
- if (value_size == 0) {
- // If `value_size == 0` here, that probably means the environment variable
- // was deleted between when we checked and when we allocated the buffer. We
- // report `None` to indicate the environment variable was not found.
- return None();
- }
-
- return std::string(environment.get());
-}
-
-
-inline tm* gmtime_r(const time_t* timep, tm* result)
-{
- return ::gmtime_s(result, timep) == ERROR_SUCCESS ? result : NULL;
-}
-
-
-inline Try<bool> access(const std::string& fileName, int how)
-{
- if (::_access(fileName.c_str(), how) != 0) {
- return ErrnoError("os::access: Call to `_access` failed for path '" +
- fileName + "'");
- }
-
- return true;
-}
-
-inline Result<PROCESSENTRY32> process_entry(pid_t pid)
-{
- // Get a snapshot of the processes in the system. NOTE: We should not check
- // whether the handle is `NULL`, because this API will always return
- // `INVALID_HANDLE_VALUE` on error.
- HANDLE snapshot_handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, pid);
- if (snapshot_handle == INVALID_HANDLE_VALUE) {
- return WindowsError(
- "os::process_entry: Call to `CreateToolhelp32Snapshot` failed");
- }
-
- SharedHandle safe_snapshot_handle(snapshot_handle, ::CloseHandle);
-
- // Initialize process entry.
- PROCESSENTRY32 process_entry;
- ZeroMemory(&process_entry, sizeof(PROCESSENTRY32));
- process_entry.dwSize = sizeof(PROCESSENTRY32);
-
- // Get first process so that we can loop through process entries until we
- // find the one we care about.
- SetLastError(ERROR_SUCCESS);
- bool has_next = Process32First(safe_snapshot_handle.get(), &process_entry);
- if (!has_next) {
- // No first process was found. We should never be here; it is arguable we
- // should return `None`, since we won't find the PID we're looking for, but
- // we elect to return `Error` because something terrible has probably
- // happened.
- if (GetLastError() != ERROR_SUCCESS) {
- return WindowsError("os::process_entry: Call to `Process32First` failed");
- } else {
- return Error("os::process_entry: Call to `Process32First` failed");
- }
- }
-
- // Loop through processes until we find the one we're looking for.
- while (has_next) {
- if (process_entry.th32ProcessID == pid) {
- // Process found.
- return process_entry;
- }
-
- has_next = Process32Next(safe_snapshot_handle.get(), &process_entry);
- if (!has_next) {
- DWORD last_error = GetLastError();
- if (last_error != ERROR_NO_MORE_FILES && last_error != ERROR_SUCCESS) {
- return WindowsError(
- "os::process_entry: Call to `Process32Next` failed");
- }
- }
- }
-
- return None();
-}
-
-
-// Generate a `Process` object for the process associated with `pid`. If
-// process is not found, we return `None`; error is reserved for the case where
-// something went wrong.
-inline Result<Process> process(pid_t pid)
-{
- // Find process with pid.
- Result<PROCESSENTRY32> entry = process_entry(pid);
-
- if (entry.isError()) {
- return WindowsError(entry.error());
- } else if (entry.isNone()) {
- return None();
- }
-
- HANDLE process_handle = ::OpenProcess(
- PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ,
- false,
- pid);
-
- if (process_handle == INVALID_HANDLE_VALUE) {
- return WindowsError("os::process: Call to `OpenProcess` failed");
- }
-
- SharedHandle safe_process_handle(process_handle, ::CloseHandle);
-
- // Get Windows Working set size (Resident set size in linux).
- PROCESS_MEMORY_COUNTERS proc_mem_counters;
- BOOL get_process_memory_info = ::GetProcessMemoryInfo(
- safe_process_handle.get(),
- &proc_mem_counters,
- sizeof(proc_mem_counters));
-
- if (!get_process_memory_info) {
- return WindowsError("os::process: Call to `GetProcessMemoryInfo` failed");
- }
-
- // Get session Id.
- pid_t session_id;
- BOOL process_id_to_session_id = ::ProcessIdToSessionId(pid, &session_id);
-
- if (!process_id_to_session_id) {
- return WindowsError("os::process: Call to `ProcessIdToSessionId` failed");
- }
-
- // Get Process CPU time.
- FILETIME create_filetime, exit_filetime, kernel_filetime, user_filetime;
- BOOL get_process_times = ::GetProcessTimes(
- safe_process_handle.get(),
- &create_filetime,
- &exit_filetime,
- &kernel_filetime,
- &user_filetime);
-
- if (!get_process_times) {
- return WindowsError("os::process: Call to `GetProcessTimes` failed");
- }
-
- // Get utime and stime.
- ULARGE_INTEGER lKernelTime, lUserTime; // In 100 nanoseconds.
- lKernelTime.HighPart = kernel_filetime.dwHighDateTime;
- lKernelTime.LowPart = kernel_filetime.dwLowDateTime;
- lUserTime.HighPart = user_filetime.dwHighDateTime;
- lUserTime.LowPart = user_filetime.dwLowDateTime;
-
- Try<Duration> utime = Nanoseconds(lKernelTime.QuadPart * 100);
- Try<Duration> stime = Nanoseconds(lUserTime.QuadPart * 100);
-
- return Process(
- pid,
- entry.get().th32ParentProcessID, // Parent process id.
- 0, // Group id.
- session_id,
- Bytes(proc_mem_counters.WorkingSetSize),
- utime.isSome() ? utime.get() : Option<Duration>::none(),
- stime.isSome() ? stime.get() : Option<Duration>::none(),
- entry.get().szExeFile, // Executable filename.
- false); // Is not zombie process.
-}
-
-
-} // namespace os {
-
-#endif // __STOUT_WINDOWS_OS_HPP__