Commit bba998f5 authored by knownexus's avatar knownexus
Browse files

Moved `resource.getrlimit()`

Removed `resource.getrlimit()` functionality from app.py
Added `resource.getrlimit()` functionality to linux.py
Added `resource.getrlimit()` functionality to unix.py
parent 6a0cdedf
Loading
Loading
Loading
Loading
+0 −8
Original line number Original line Diff line number Diff line
@@ -116,14 +116,6 @@ class App():
        else:
        else:
            self.colors = False
            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()
    # create()
    #
    #
    # Should be used instead of the regular constructor.
    # Should be used instead of the regular constructor.
+8 −1
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import subprocess


from .. import _site
from .. import _site
from .. import utils
from .. import utils
import resource
from .._artifactcache.cascache import CASCache
from .._artifactcache.cascache import CASCache
from .._message import Message, MessageType
from .._message import Message, MessageType
from ..sandbox import SandboxBwrap
from ..sandbox import SandboxBwrap
@@ -38,6 +39,13 @@ class Linux(Platform):
        self._user_ns_available = self._check_user_ns_available(context)
        self._user_ns_available = self._check_user_ns_available(context)
        self._artifact_cache = CASCache(context, enable_push=self._user_ns_available)
        self._artifact_cache = CASCache(context, enable_push=self._user_ns_available)


        # 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]:
            resource.setrlimit(resource.RLIMIT_NOFILE, (limits[1], limits[1]))

    @property
    @property
    def artifactcache(self):
    def artifactcache(self):
        return self._artifact_cache
        return self._artifact_cache
@@ -52,7 +60,6 @@ class Linux(Platform):
    #              Private Methods                 #
    #              Private Methods                 #
    ################################################
    ################################################
    def _check_user_ns_available(self, context):
    def _check_user_ns_available(self, context):

        # Here, lets check if bwrap is able to create user namespaces,
        # Here, lets check if bwrap is able to create user namespaces,
        # issue a warning if it's not available, and save the state
        # issue a warning if it's not available, and save the state
        # locally so that we can inform the sandbox to not try it
        # locally so that we can inform the sandbox to not try it
+8 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
#        Tristan Maat <tristan.maat@codethink.co.uk>
#        Tristan Maat <tristan.maat@codethink.co.uk>


import os
import os
import resource


from .._artifactcache.cascache import CASCache
from .._artifactcache.cascache import CASCache
from .._exceptions import PlatformError
from .._exceptions import PlatformError
@@ -33,6 +34,13 @@ class Unix(Platform):
        super().__init__(context)
        super().__init__(context)
        self._artifact_cache = CASCache(context)
        self._artifact_cache = CASCache(context)


        # 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]:
            resource.setrlimit(resource.RLIMIT_NOFILE, (limits[1], limits[1]))

        # Not necessarily 100% reliable, but we want to fail early.
        # Not necessarily 100% reliable, but we want to fail early.
        if os.geteuid() != 0:
        if os.geteuid() != 0:
            raise PlatformError("Root privileges are required to run without bubblewrap.")
            raise PlatformError("Root privileges are required to run without bubblewrap.")