[net.bugs.4bsd] Bug in 4.2 csh unlimit command

sid@linus.UUCP (Sid Stuart) (06/30/84)

Index: csh 4.2 unlimit sh.func.c

Description: In going from 4.1 to 4.2, Berkeley changed the interface to
the resource allocation in the kernal, in 4.1 the interface was a library
call, vlimit; in 4.2 the interface is a system call to getrlimit or
setrlimit. The semantics have changed also. The limits are held in a per
user structure that holds two integers, one for the current limit and one
for the maximum limit. The user can change the current level integer
within the range 0 to max_limit. He can also lower the max_limit integer,
but he cannot raise it (kind of like nice). There is also an infinity setting
that is a large negative number. 
	In the csh when one types unlimit, the shell trys to set all of the
various resource values to the infinity constant. Unfortunatly, the
max_limit settings for some of these values are less than the infinity
constant and so setrlimit barfs up an error message like

	"limit: Not owner"

This can be fixed by going into /usr/src/bin/csh/sh.func.c and
modifying the setlim command to set the current limit to the
maximum limit when it sees the infinity constant come in. See the
diffs below.

Note, as I understand the behavior of 4.1, if you gave the limit
command a value that was larger than the upper bounds of that
resource, it just set it at the upper bounds. (I have not looked at the
code). This behavior is changed in 4.2, if you give a larger value
than max_limit, you get the above pithy message. I decided that
I like that latter behavior, once you get used to the change, as
it makes you aware that you can not change that setting to that
value.


Repeat by: get into the csh and type "unlimit"

Fix:

*** sh.func.orig	Sat Jun 23 13:43:32 1984
--- sh.func.c	Sat Jun 23 13:42:57 1984
***************
*** 995,1001
  	struct rlimit rlim;
  
  	getrlimit(lp->limconst, &rlim);
! 	rlim.rlim_cur = limit;
  	if (setrlimit(lp->limconst, &rlim) < 0)
  		Perror(bname);
  }

--- 995,1013 -----
  	struct rlimit rlim;
  
  	getrlimit(lp->limconst, &rlim);
! 
! /* 	Fix the unlimit command, if the passed limit is set to infinity	*
!  *	then set the current limit to the max limit, which is as high	*
!  *	as a normal user can set it. If it is				*
!  *	the superuser, let him set it to to be what he wants.		*
!  *			sid, June 23 1984.				*/
! 
! 
!  	if(limit == RLIM_INFINITY && geteuid() != 0)
! 		rlim.rlim_cur = rlim.rlim_max;
! 	else
! 		rlim.rlim_cur = limit;     
! 
  	if (setrlimit(lp->limconst, &rlim) < 0)
  		Perror(bname);
  }