This is an automated email from the ASF dual-hosted git repository. jpeach pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 4bd3e7023bcbe88c9ad1defdf9a138c8c78b377f Author: Jacob Janco <[email protected]> AuthorDate: Sat Jul 20 23:34:12 2019 -0700 Moved kernelVersion check to common code. Review: https://reviews.apache.org/r/71106/ --- src/CMakeLists.txt | 1 + src/Makefile.am | 2 ++ src/common/kernel_version.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++ src/common/kernel_version.hpp | 29 +++++++++++++++++++++++++ src/linux/ns.cpp | 23 ++------------------ 5 files changed, 84 insertions(+), 21 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 99402cb..4a5eeb0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -237,6 +237,7 @@ set(COMMON_SRC common/build.cpp common/command_utils.cpp common/http.cpp + common/kernel_version.cpp common/protobuf_utils.cpp common/resources.cpp common/resource_quantities.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 3c600bd..7851aba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1071,6 +1071,8 @@ libmesos_no_3rdparty_la_SOURCES += \ common/heartbeater.hpp \ common/http.cpp \ common/http.hpp \ + common/kernel_version.cpp \ + common/kernel_version.hpp \ common/parse.hpp \ common/protobuf_utils.cpp \ common/protobuf_utils.hpp \ diff --git a/src/common/kernel_version.cpp b/src/common/kernel_version.cpp new file mode 100644 index 0000000..51882f9 --- /dev/null +++ b/src/common/kernel_version.cpp @@ -0,0 +1,50 @@ +// 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. + +#include <string> + +#include <stout/os.hpp> +#include <stout/strings.hpp> +#include <stout/try.hpp> +#include <stout/version.hpp> + +#include <common/kernel_version.hpp> + +using std::string; +using std::vector; + +namespace mesos { + +Try<Version> kernelVersion() +{ + Try<os::UTSInfo> uname = os::uname(); + if (!uname.isSome()) { + return Error("Unable to determine kernel version: " + uname.error()); + } + + vector<string> parts = strings::split(uname->release, "."); + parts.resize(2); + + Try<Version> version = Version::parse(strings::join(".", parts)); + if (!version.isSome()) { + return Error("Failed to parse kernel version '" + uname->release + + "': " + version.error()); + } + + return version; +} + +} // namespace mesos { diff --git a/src/common/kernel_version.hpp b/src/common/kernel_version.hpp new file mode 100644 index 0000000..e5f72bf --- /dev/null +++ b/src/common/kernel_version.hpp @@ -0,0 +1,29 @@ +// 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 __KERNEL_VERSION_HPP__ +#define __KERNEL_VERSION_HPP__ + +#include <stout/try.hpp> +#include <stout/version.hpp> + +namespace mesos { + +Try<Version> kernelVersion(); + +} // namespace mesos { + +#endif // __KERNEL_VERSION_HPP__ diff --git a/src/linux/ns.cpp b/src/linux/ns.cpp index 2440bb2..32d3e05 100644 --- a/src/linux/ns.cpp +++ b/src/linux/ns.cpp @@ -46,6 +46,7 @@ #include <stout/os/ls.hpp> #include <stout/os/socket.hpp> +#include "common/kernel_version.hpp" #include "common/status_utils.hpp" using std::set; @@ -54,26 +55,6 @@ using std::vector; namespace ns { -static Try<Version> kernelVersion() -{ - Try<os::UTSInfo> uname = os::uname(); - if (!uname.isSome()) { - return Error("Unable to determine kernel version: " + uname.error()); - } - - vector<string> parts = strings::split(uname->release, "."); - parts.resize(2); - - Try<Version> version = Version::parse(strings::join(".", parts)); - if (!version.isSome()) { - return Error("Failed to parse kernel version '" + uname->release + - "': " + version.error()); - } - - return version; -} - - Try<int> nstype(const string& ns) { const hashmap<string, int> nstypes = { @@ -166,7 +147,7 @@ Try<bool> supported(int nsTypes) } if ((nsTypes & CLONE_NEWUSER) && (supported & CLONE_NEWUSER)) { - Try<Version> version = kernelVersion(); + Try<Version> version = mesos::kernelVersion(); if (version.isError()) { return Error(version.error());
