diff --git a/repos/base-linux/src/core/include/core_linux_syscalls.h b/repos/base-linux/src/core/include/core_linux_syscalls.h index c3bd08514e..a18e77d442 100644 --- a/repos/base-linux/src/core/include/core_linux_syscalls.h +++ b/repos/base-linux/src/core/include/core_linux_syscalls.h @@ -19,6 +19,7 @@ #define size_t __SIZE_TYPE__ /* see comment in 'linux_syscalls.h' */ #include +#include #include #undef size_t @@ -72,6 +73,7 @@ inline int lx_stat(const char *path, struct stat64 *buf) #endif } + /*********************************************************** ** Functions used by core's io port session support code ** ***********************************************************/ @@ -180,6 +182,27 @@ inline void lx_disable_aslr() } +/*********************************** + ** Resource-limit initialization ** + ***********************************/ + +inline void lx_boost_rlimit() +{ + rlimit rlimit { }; + + if (int const res = lx_syscall(SYS_getrlimit, RLIMIT_NOFILE, &rlimit)) { + Genode::warning("unable to obtain RLIMIT_NOFILE (", res, "), keeping limit unchanged"); + return; + } + + /* increase soft limit to hard limit */ + rlimit.rlim_cur = rlimit.rlim_max; + + if (int const res = lx_syscall(SYS_setrlimit, RLIMIT_NOFILE, &rlimit)) + Genode::warning("unable to boost RLIMIT_NOFILE (", res, "), keeping limit unchanged"); +} + + /******************************************** ** Communication over Unix-domain sockets ** ********************************************/ diff --git a/repos/base-linux/src/core/platform.cc b/repos/base-linux/src/core/platform.cc index 927baf19c2..d4ff1d7fb1 100644 --- a/repos/base-linux/src/core/platform.cc +++ b/repos/base-linux/src/core/platform.cc @@ -94,6 +94,9 @@ Platform::Platform() /* make 'mmap' behave deterministically */ lx_disable_aslr(); + /* increase maximum number of open file descriptors to the hard limit */ + lx_boost_rlimit(); + /* catch control-c */ lx_sigaction(LX_SIGINT, sigint_handler, false); diff --git a/repos/gems/run/leitzentrale.run b/repos/gems/run/leitzentrale.run index 6dc91398e3..cded4fe7c3 100644 --- a/repos/gems/run/leitzentrale.run +++ b/repos/gems/run/leitzentrale.run @@ -350,15 +350,5 @@ build { server/lx_block app/menu_view app/sculpt_manager } build_boot_image { lx_block menu_view sculpt_manager ahci-1.img } -if {[have_spec linux]} { - set max_fds [exec bash -c "ulimit -n"] - if {$max_fds < 4096} { - puts stderr "\nMaximum number of file descriptors is too low for this run script." - puts stderr "You may use the following command to increase the limit:\n" - puts stderr " ulimit -n 4096\n" - exit 1 - } -} - run_genode_until forever diff --git a/repos/gems/run/tiled_wm.run b/repos/gems/run/tiled_wm.run index ca92383506..8c9a11fcea 100644 --- a/repos/gems/run/tiled_wm.run +++ b/repos/gems/run/tiled_wm.run @@ -12,15 +12,6 @@ if {[have_spec odroid_xu]} { exit 0 } -if {[have_spec linux]} { - set max_fds [exec bash -c "ulimit -n"] - if {$max_fds < 4096} { - puts stderr "\nMaximum number of file descriptors is too low for this run script." - puts stderr "You may use the following command to increase the limit:\n" - puts stderr " ulimit -n 4096\n" - exit 1 - } -} # # Generate config