From d0bfe9a66103d962c1d396295391dfaec06af05a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 26 Jun 2019 13:44:58 +0800 Subject: [PATCH] Adjust open file descriptor limit on startup This raises qbt's open file descriptor limit to the available maximum (within user privileges) and thus users don't need to adjust it manually anymore. --- src/app/main.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/app/main.cpp b/src/app/main.cpp index b17f6ce7a..31a4a6ccb 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -33,6 +33,9 @@ #include #include +#if defined(Q_OS_UNIX) +#include +#endif #if !defined Q_OS_WIN && !defined Q_OS_HAIKU #include #elif defined Q_OS_WIN && defined DISABLE_GUI @@ -116,9 +119,17 @@ void displayBadArgMessage(const QString &message); void showSplashScreen(); #endif // DISABLE_GUI +#if defined(Q_OS_UNIX) +void adjustFileDescriptorLimit(); +#endif + // Main int main(int argc, char *argv[]) { +#if defined(Q_OS_UNIX) + adjustFileDescriptorLimit(); +#endif + // We must save it here because QApplication constructor may change it bool isOneArg = (argc == 2); @@ -397,3 +408,16 @@ bool userAgreesWithLegalNotice() return false; } + +#if defined(Q_OS_UNIX) +void adjustFileDescriptorLimit() +{ + rlimit limit {}; + + if (getrlimit(RLIMIT_NOFILE, &limit) != 0) + return; + + limit.rlim_cur = limit.rlim_max; + setrlimit(RLIMIT_NOFILE, &limit); +} +#endif