]> git.saurik.com Git - redis.git/commitdiff
When the user-provided 'maxclients' value is too big for the max number of files...
authorantirez <antirez@gmail.com>
Tue, 3 Apr 2012 09:53:45 +0000 (11:53 +0200)
committerantirez <antirez@gmail.com>
Tue, 3 Apr 2012 12:55:18 +0000 (14:55 +0200)
src/redis.c

index 557b361a5bb6d2c702951ae485e6c6c7d686d3a0..0bff9339143385ab23b5313d9427e3b017dcf4ff 100644 (file)
@@ -1124,10 +1124,18 @@ void adjustOpenFilesLimit(void) {
         /* Set the max number of files if the current limit is not enough
          * for our needs. */
         if (oldlimit < maxfiles) {
-            limit.rlim_cur = maxfiles;
-            limit.rlim_max = maxfiles;
-            if (setrlimit(RLIMIT_NOFILE,&limit) == -1) {
-                server.maxclients = oldlimit-32;
+            rlim_t f;
+            
+            f = maxfiles;
+            while(f > oldlimit) {
+                limit.rlim_cur = f;
+                limit.rlim_max = f;
+                if (setrlimit(RLIMIT_NOFILE,&limit) != -1) break;
+                f -= 128;
+            }
+            if (f < oldlimit) f = oldlimit;
+            if (f != maxfiles) {
+                server.maxclients = f-32;
                 redisLog(REDIS_WARNING,"Unable to set the max number of files limit to %d (%s), setting the max clients configuration to %d.",
                     (int) maxfiles, strerror(errno), (int) server.maxclients);
             } else {