Lawrence Greenfield wrote:
> 
> Can someone with a FreeBSD/OpenBSD machine please read the
> documentation for setrlimit() and find out what's going wrong with the
> current code?

Well, the debug output says:

Feb  5 19:50:15 inky master[12991]: set maximum file descriptors to
256/0

Which would indicate that it doesn't increase the rlim_cur properly.  It
looks like there's some overflow happening.  rlim_t on OpenBSD is a
64-bit integer (well, a int64_t or quad_t), which is distinctly not an
int.

A simple test program, listed below, seems to work better with rlim_t
than int.  All that I did was change the argument to limit_fds from an
int to a rlim_t (line 6).  Here's the outputs with int and rlim_t:

--- BEGIN int ---
inky# gcc -Wall master.c -o master
master.c: In function `limit_fds':
master.c:20: warning: int format, different type arg (arg 2)
master.c:20: warning: int format, different type arg (arg 3)
master.c: In function `main':
master.c:24: warning: overflow in implicit constant conversion
master.c:25: warning: overflow in implicit constant conversion
inky# ./master
setrlimit: Invalid argument
unable to unlimit the number of file descriptors avialable
set maximum file descriptors to 128/0
setrlimit: Invalid argument
unable to unlimit the number of file descriptors avialable
set maximum file descriptors to 128/0
--- END int ---

--- BEGIN rlim_t ---
inky# gcc -Wall master.c -o master
master.c: In function `limit_fds':
master.c:20: warning: int format, different type arg (arg 2)
master.c:20: warning: int format, different type arg (arg 3)
inky# ./master
set maximum file descriptors to 1772/0
set maximum file descriptors to 1772/0
--- END rlim_t ---

I don't understand the 1772 thing, though.  If I fix the %d to %qd, then
the warnings go away, but I get 1772/1772.  That's all as root, btw, so
there should be no limit on setting the limit.

-Bitt


--- BEGIN ---
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>

void limit_fds(rlim_t x)
{
    struct rlimit rl;
    int r;

    rl.rlim_cur = x;
    rl.rlim_max = x;
    if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
        perror("setrlimit");
        printf("unable to unlimit the number of file descriptors
avialable\n");
    }

    r = getrlimit(RLIMIT_NOFILE, &rl);
    printf("set maximum file descriptors to %d/%d\n", rl.rlim_cur,
           rl.rlim_max);
}

int main(void) {
        limit_fds(RLIM_INFINITY);
        limit_fds(RLIM_INFINITY);
        return(0);
}
--- END ---

Reply via email to