summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknownexus <phillip.smyth@codethink.co.uk>2018-08-30 11:45:53 +0100
committerPhillip Smyth <phillip.smyth@codethink.co.uk>2018-09-25 15:54:46 +0100
commit33cf91ceac15964366a3f8b97ff81ed53cc4c2a3 (patch)
treef1d0984f2420e1d0b8e5f735ad068eb4c1ab2fa7
parent8cea7b17a773230e37a84b1c0fccadb23f24a108 (diff)
downloadbuildstream-33cf91ceac15964366a3f8b97ff81ed53cc4c2a3.tar.gz
Added `set_resource_limits()` to platform
This has been moved from app.py As it will have different functionality depending on platform Once the Darwin (MacOS) platform is added Removed `resource.setrlimit()` functionality from app.py Added `resource.setrlimit()` functionality to platform.py as function
-rw-r--r--buildstream/_frontend/app.py8
-rw-r--r--buildstream/_platform/linux.py1
-rw-r--r--buildstream/_platform/platform.py14
3 files changed, 14 insertions, 9 deletions
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index ccdbb2d5d..44b4cfb95 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -115,14 +115,6 @@ class App():
else:
self.colors = False
- # Increase the soft limit for open file descriptors to the maximum.
- # SafeHardlinks FUSE needs to hold file descriptors for all processes in the sandbox.
- # Avoid hitting the limit too quickly.
- limits = resource.getrlimit(resource.RLIMIT_NOFILE)
- if limits[0] != limits[1]:
- # Set soft limit to hard limit
- resource.setrlimit(resource.RLIMIT_NOFILE, (limits[1], limits[1]))
-
# create()
#
# Should be used instead of the regular constructor.
diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py
index a5fd0d687..d29a1d575 100644
--- a/buildstream/_platform/linux.py
+++ b/buildstream/_platform/linux.py
@@ -52,7 +52,6 @@ class Linux(Platform):
# Private Methods #
################################################
def _check_user_ns_available(self, context):
-
# Here, lets check if bwrap is able to create user namespaces,
# issue a warning if it's not available, and save the state
# locally so that we can inform the sandbox to not try it
diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py
index 8a074eb62..a10c66da9 100644
--- a/buildstream/_platform/platform.py
+++ b/buildstream/_platform/platform.py
@@ -19,6 +19,7 @@
import os
import sys
+import resource
from .._exceptions import PlatformError, ImplError
@@ -37,6 +38,7 @@ class Platform():
#
def __init__(self, context):
self.context = context
+ self.set_resource_limits()
@classmethod
def create_instance(cls, *args, **kwargs):
@@ -92,3 +94,15 @@ class Platform():
def create_sandbox(self, *args, **kwargs):
raise ImplError("Platform {platform} does not implement create_sandbox()"
.format(platform=type(self).__name__))
+
+ def set_resource_limits(self, soft_limit=None, hard_limit=None):
+ # Need to set resources for _frontend/app.py as this is dependent on the platform
+ # SafeHardlinks FUSE needs to hold file descriptors for all processes in the sandbox.
+ # Avoid hitting the limit too quickly.
+ limits = resource.getrlimit(resource.RLIMIT_NOFILE)
+ if limits[0] != limits[1]:
+ if soft_limit is None:
+ soft_limit = limits[1]
+ if hard_limit is None:
+ hard_limit = limits[1]
+ resource.setrlimit(resource.RLIMIT_NOFILE, (soft_limit, hard_limit))