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:
1 parent
3ef30e759e
commit
0d1f4fd471
4 files changed
+52
No files matched your search
@@ -70,6 +70,8 @@ qboolean Sys_PIDIsRunning( int pid );
|
||||
|
||||
qboolean Sys_OpenFolderInPlatformFileManager( const char *path );
|
||||
|
||||
qboolean Sys_SetMaxFileLimit( void );
|
||||
|
||||
#ifdef PROTOCOL_HANDLER
|
||||
char *Sys_ParseProtocolUri( const char *uri );
|
||||
#endif
|
||||
|
||||
@@ -823,6 +823,7 @@ int main( int argc, char **argv )
|
||||
#endif
|
||||
|
||||
Sys_PlatformInit( );
|
||||
Sys_SetMaxFileLimit( );
|
||||
|
||||
// Set the initial time base
|
||||
Sys_Milliseconds( );
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -929,3 +929,13 @@ qboolean Sys_OpenFolderInPlatformFileManager( const char *path )
|
||||
{
|
||||
return ShellExecute( NULL, "explore", path, NULL, NULL, SW_SHOWDEFAULT ) > (HINSTANCE)32;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Sys_SetMaxFileLimit
|
||||
=================
|
||||
*/
|
||||
qboolean Sys_SetMaxFileLimit( void )
|
||||
{
|
||||
return qtrue;
|
||||
}
|
||||
Reference in new issue
Block a user