You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ti...@apache.org on 2018/11/24 01:22:32 UTC
[mesos] 01/02: Added a function to get rlimits.
This is an automated email from the ASF dual-hosted git repository.
tillt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 0db5e7feff9f4fe6b27c0a3baca2339266519068
Author: Benjamin Bannier <be...@mesosphere.io>
AuthorDate: Sat Nov 24 02:18:35 2018 +0100
Added a function to get rlimits.
Review: https://reviews.apache.org/r/67136/
---
src/posix/rlimits.cpp | 27 ++++++++++++++++++++++++++-
src/posix/rlimits.hpp | 3 +++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/src/posix/rlimits.cpp b/src/posix/rlimits.cpp
index 6446c14..18a06c3 100644
--- a/src/posix/rlimits.cpp
+++ b/src/posix/rlimits.cpp
@@ -127,12 +127,37 @@ Try<Nothing> set(const RLimitInfo::RLimit& limit)
}
if (setrlimit(resource.get(), &resourceLimit) != 0) {
- return Error("Failed to set rlimit: " + os::strerror(errno));
+ return ErrnoError();
}
return Nothing();
}
+
+Try<RLimitInfo::RLimit> get(RLimitInfo::RLimit::Type type)
+{
+ Try<int> _type = rlimits::convert(type);
+ if (_type.isError()) {
+ return Error(_type.error());
+ }
+
+ ::rlimit resourceLimit;
+ if (getrlimit(_type.get(), &resourceLimit) != 0) {
+ return ErrnoError();
+ }
+
+ RLimitInfo::RLimit limit;
+ limit.set_type(type);
+ if (resourceLimit.rlim_cur != RLIM_INFINITY) {
+ limit.set_soft(resourceLimit.rlim_cur);
+ }
+ if (resourceLimit.rlim_max != RLIM_INFINITY) {
+ limit.set_hard(resourceLimit.rlim_max);
+ }
+
+ return std::move(limit);
+}
+
} // namespace rlimits {
} // namespace internal {
} // namespace mesos {
diff --git a/src/posix/rlimits.hpp b/src/posix/rlimits.hpp
index 0cc4d8a..fd99e05 100644
--- a/src/posix/rlimits.hpp
+++ b/src/posix/rlimits.hpp
@@ -34,6 +34,9 @@ Try<int> convert(RLimitInfo::RLimit::Type type);
// Set the given resource limit for the calling process.
Try<Nothing> set(const RLimitInfo::RLimit& limit);
+// Get the given resource limit for the calling process.
+Try<RLimitInfo::RLimit> get(RLimitInfo::RLimit::Type type);
+
} // namespace rlimits {
} // namespace internal {
} // namespace mesos {