Subject: Re: kern/36153: getrusage(2) not working?
To: None <gnats-bugs@NetBSD.org>
From: Juan RP <juan@xtrarom.org>
List: netbsd-bugs
Date: 04/16/2007 13:41:28
On Mon, 16 Apr 2007 10:45:01 +0000 (UTC)
juan@xtrarom.org wrote:

Erm... that should be getrlimit(2).

Can anyone explain that?
                                                                                         
time(cpu-seconds)    unlimited
file(blocks)         unlimited
coredump(blocks)     unlimited
data(kbytes)         524288
stack(kbytes)        4096
lockedmem(kbytes)    669930
memory(kbytes)       1048576
nofiles(descriptors) 64
processes            64
sbsize(bytes)        unlimited

$ echo $((536870912/1024))
524288

$ ./setlimit 546870912
rlim_cur (after) =536870912
rlim_max (before) =536870912
Unknown error: 4294967295

$ ./setlimit 526870912 
rlim_cur (after) =536870912
rlim_max (before) =536870912
rlim_cur (after) =526870912
rlim_max (before) =536870912

$ ./setlimit 516870912 
rlim_cur (after) =536870912
rlim_max (before) =536870912
rlim_cur (after) =516870912
rlim_max (before) =536870912
$


$ cat setlimit.c 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <err.h>
#include <errno.h>
#include <sys/resource.h>

int main(int argc, char **argv)
{
        struct rlimit rlim;
        char *buf;
        int rval = 0;

        if (argc != 2)
           return EINVAL;

        if ((getrlimit(RLIMIT_DATA, &rlim)) < 0)
           perror("getrlimit");

        printf("rlim_cur (after) =%ld\n", rlim.rlim_cur);
        printf("rlim_max (before) =%ld\n", rlim.rlim_max);

        rlim.rlim_cur = strtol(argv[1], &buf, 10);
        if (*buf != '\0')
           err(EINVAL, "not a number");

        if ((rval = setrlimit(RLIMIT_DATA, &rlim)) < 0) {
           printf("%s\n", strerror(rval));
           return rval;
        }

        if ((getrlimit(RLIMIT_DATA, &rlim)) < 0)
           perror("getrlimit");

        printf("rlim_cur (after) =%ld\n", rlim.rlim_cur);
        printf("rlim_max (before) =%ld\n", rlim.rlim_max);

        return 0;
}

ktruss reports:

 29237      1 setlimit setrlimit(0x2, 0x7f7fffffe830) = 0
 29237      1 setlimit getrlimit(0x2, 0x7f7fffffe830) = 0

-- 
http://plog.xtrarom.org/
Juan RP's blog - NetBSD/pkgsrc news in Spanish