In the following code:
139 struct rlimit limit;
140
141 method = "rlimit";
142 if (getrlimit(RLIMIT_NOFILE, &limit) < 0) {
143 perror("calling getrlimit");
144 exit(1);
145 }
146
147 /* set the current to the maximum or specified value */
148 if (max_desired_fds)
149 limit.rlim_cur = max_desired_fds;
150 else {
151 limit.rlim_cur = limit.rlim_max;
152 }
153
154 if (setrlimit(RLIMIT_NOFILE, &limit) < 0) {
155 perror("calling setrlimit");
156 exit(1);
157 }
the setrlimit line fails (I get the error "calling setrlimit"). Further investigation shows that limit.rlim_max
is -1, which is not a valid value. Any ideas why would this be? This is on Mac OSX.
If setrlimit
fails, try again with rlim_cur
set to OPEN_MAX
. For example, see http://source.winehq.org/source/libs/wine/loader.c#L653. (The comment mentioning Leopard means that Leopard first introduced that behavior. Read it as Leopard-and-later.)
ETA: See the note in COMPATIBILITY in the setrlimit(2) man page.