Skip to content
Snippets Groups Projects
Commit 8eedddc4 authored by knownexus's avatar knownexus Committed by Phillip Smyth
Browse files

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
parent 1b2aed40
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
......@@ -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
......
......@@ -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))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment