Set the maximum file limit for POSIX systems

Resolves an issue where the macOS application's dylibs could not be
loaded because there were too many maps; on macOS the default maximum
number of open files is 256.
This commit is contained in:
Allen Cronce authored and Tim Angus committed 2026-01-12 18:01:35 +00:00
1 parent 3ef30e759e
commit 0d1f4fd471
4 files changed
+52

No files matched your search

+39
View File
@@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <fenv.h>
#include <sys/wait.h>
#include <time.h>
#include <sys/resource.h>
qboolean stdinIsATTY;
@@ -1326,3 +1327,41 @@ qboolean Sys_OpenFolderInPlatformFileManager( const char *path )
return Sys_Exec( ) == 0;
}
/*
=================
Sys_SetMaxFileLimit
=================
*/
qboolean Sys_SetMaxFileLimit( void )
{
#ifdef RLIMIT_NOFILE
struct rlimit limit;
// Get the current open file limit
if( getrlimit( RLIMIT_NOFILE, &limit ) == 0 )
{
// Set the file limit to the maximum
limit.rlim_cur = limit.rlim_max;
if( setrlimit( RLIMIT_NOFILE, &limit ) == 0 )
return qtrue;
else
Com_DPrintf( S_COLOR_YELLOW "WARNING: setrlimit (rlim_max) failed\n" );
#ifdef OPEN_MAX
// On older macOS versions an error can happen trying to set a file limit above
// OPEN_MAX. If we see an error, then try again with OPEN_MAX as the limit.
limit.rlim_cur = OPEN_MAX;
if( setrlimit( RLIMIT_NOFILE, &limit ) == 0 )
return qtrue;
else
Com_DPrintf( S_COLOR_YELLOW "WARNING: setrlimit (OPEN_MAX) failed\n" );
#endif
}
else
Com_DPrintf( S_COLOR_YELLOW "WARNING: getrlimit failed\n" );
#endif // RLIMIT_NOFILE
return qfalse;
}