antirez/redis — pull request #1630 by mattsta (2014-03-23 00:08:55+00:00)
Title: Fix infinite loop ulimit

This series of patches fixes:
- two unsigned integer wraparounds
- one infinite loop
- one configuration parsing error
- one automatic reconfiguration error edge case
- error messages, hopefully making them more useful

I'm unsure about one change: instead of reserving `server.maxclients+32` fds, I changed it to `server.maxclients+REDIS_EVENTLOOP_FDSET_INCR` to equal how the server event loop is configured at https://github.com/antirez/redis/blob/unstable/src/redis.c#L1639

Thanks to @bs3g for spontaneously closing #1227 which made me look at #356 too. Sorry I couldn't use the patches in #1227, but all of those fixes eventually got implemented in these commits.

## New ulimit Error Message Output
```haskell
matt@ununoctium:~/repos/redis/src% ./redis-server
[9326] 23 Mar 00:04:16.675 # Failed to set max file limit. You requested maxclients of 10000 but your 'ulimit -n' is set to 3. Please increase your 'ulimit -n' to at least 10128.

matt@ununoctium:~/repos/redis/src% ./redis-server
[9719] 22 Mar 20:05:01.768 # Your current 'ulimit -n' of 32 is not enough for Redis to start. Please increase your open file limit to at least 10128. Exiting.

matt@ununoctium:~/repos/redis/src% ulimit -n 129
matt@ununoctium:~/repos/redis/src% ./redis-server
[9991] 22 Mar 20:05:31.896 # You requested maxclients of 10000 requiring at least 10128 max file descriptors.
[9991] 22 Mar 20:05:31.896 # Redis can't set maximum open files to 10128 because of OS error: Operation not permitted.
[9991] 22 Mar 20:05:31.896 # Current maximum open files is 129. maxclients has been reduced to 1 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.

matt@ununoctium:~/repos/redis/src% ulimit -n 3000
matt@ununoctium:~/repos/redis/src% ./redis-server
[10234] 22 Mar 20:05:58.653 # You requested maxclients of 10000 requiring at least 10128 max file descriptors.
[10234] 22 Mar 20:05:58.653 # Redis can't set maximum open files to 10128 because of OS error: Operation not permitted.
[10234] 22 Mar 20:05:58.653 # Current maximum open files is 3000. maxclients has been reduced to 2872 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.

umatt@ununoctium:~/repos/redis/src% ulimit -n 12000
matt@ununoctium:~/repos/redis/src% ./redis-server
[starts normally]
```