From 718be22d0d0bd48f90228b61958cbf0dc43160cb Mon Sep 17 00:00:00 2001 From: John Maguire Date: Tue, 21 Dec 2010 15:48:30 +0000 Subject: [PATCH] Automatically bump the max file descriptors for clementine to the maximum on Mac. --- src/main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 26c5587cc..f282b9e36 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,6 +53,11 @@ #include +#ifdef Q_OS_DARWIN + #include + #include +#endif + #ifdef HAVE_LIBLASTFM #include "radio/lastfmservice.h" @@ -102,6 +107,23 @@ int main(int argc, char *argv[]) { // Do Mac specific startup to get media keys working. // This must go before QApplication initialisation. mac::MacMain(); + + // Bump the soft limit for the number of file descriptors from the default of 256 to + // the maximum (usually 1024). + struct rlimit limit; + getrlimit(RLIMIT_NOFILE, &limit); + + // getrlimit() lies about the hard limit so we have to check sysctl. + int max_fd = 0; + size_t len = sizeof(max_fd); + sysctlbyname("kern.maxfilesperproc", &max_fd, &len, NULL, 0); + + limit.rlim_cur = max_fd; + int ret = setrlimit(RLIMIT_NOFILE, &limit); + + if (ret == 0) { + qDebug() << "Max fd:" << max_fd; + } #endif QCoreApplication::setApplicationName("Clementine");