From nobody  Wed Jan 20 16:09:33 1999
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.8/8.8.8) id QAA07127;
          Wed, 20 Jan 1999 16:09:33 -0800 (PST)
          (envelope-from nobody)
Message-Id: <199901210009.QAA07127@hub.freebsd.org>
Date: Wed, 20 Jan 1999 16:09:33 -0800 (PST)
From: jplevyak@inktomi.com
To: freebsd-gnats-submit@freebsd.org
Subject: Linux compat getrlimit/setrlimit constants wrong
X-Send-Pr-Version: www-1.0

>Number:         9591
>Category:       kern
>Synopsis:       Linux compat getrlimit/setrlimit constants wrong
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 20 16:10:01 PST 1999
>Closed-Date:    Wed Aug 11 06:36:46 PDT 1999
>Last-Modified:  Wed Aug 11 06:38:48 PDT 1999
>Originator:     John Plevyak
>Release:        3.0-Current Jan 12, 1999
>Organization:
Inktomi
>Environment:
FreeBSD cobalt.inktomi.com 3.0-CURRENT FreeBSD 3.0-CURRENT #6: Wed Jan 20 15:37:56 PST 1999     jplevyak@cobalt.inktomi.com:/usr/src/sys/compile/INKTOMI  i386

>Description:
On Linux RLIMIT_NOFILE is 7,  On FreeBSD it is 8.
in /usr/src/sys/i386/linux there is no translation, and
the values are passed through, resulting in the wrong
limit being set/got.

>How-To-Repeat:
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/socket.h>

main() {
  struct rlimit rl;
  int i;
  printf("%d\n", getrlimit(RLIMIT_NOFILE, &rl));
  printf("%d %d\n", (int)rl.rlim_cur, (int)rl.rlim_max);
  for (i=1;i<30000;i++) {
    if (!(i%1000)) printf("%d\n", i);
    if (socket(PF_INET,SOCK_STREAM,0)<0) break;
  }
  printf("%d %d\n", i, errno);
}


compiled on linux and run on FreeBSD
with 16386 max files results in:

% ./a.out
0
531 531
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
11000
12000
13000
14000
15000
16000
16382 24

% sysctl kern.maxfilesperproc
kern.maxfilesperproc: 16384
>Fix:
Put in a jump function with the appropriate translation.
I can provide a patch.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: fenner 
Responsible-Changed-When: Fri Jan 22 13:03:56 PST 1999 
Responsible-Changed-Why:  
Fixing misfiled PR. 
State-Changed-From-To: open->closed 
State-Changed-By: marcel 
State-Changed-When: Wed Aug 11 06:36:46 PDT 1999 
State-Changed-Why:  
The Linux emulator has been fixed and the problem solved. Thanks for the PR and 
the source code to clarify the problem! 
>Unformatted:
