* resource.cc (getrlimit): Set errno on EFAULT instead of returning it.

(setrlimit): Ditto.

        Patch by David Sainty <David.Sainty@optimation.co.nz>:
        * resource.cc (setrlimit): Prevent failing with an error when the
        operation would not have changed anything.
This commit is contained in:
Corinna Vinschen 2001-01-05 09:01:18 +00:00
parent a5e570bcc3
commit f3236259b4
2 changed files with 33 additions and 3 deletions

View File

@ -1,3 +1,14 @@
Thu Jan 5 9:33:00 2001 Corinna Vinschen <corina@vinschen.de>
* resource.cc (getrlimit): Set errno on EFAULT instead of returning
it.
(setrlimit): Ditto.
Thu Jan 5 3:38:00 2001 David Sainty <David.Sainty@optimation.co.nz>
* resource.cc (setrlimit): Prevent failing with an error when the
operation would not have changed anything.
Thu Jan 4 10:29:54 2001 Earnie Boyd <earnie_boyd@yahoo.com>
* thread.cc: Need LONG_MAX definition.

View File

@ -1,6 +1,6 @@
/* resource.cc: getrusage () and friends.
Copyright 1996, 1997, 1998, 2000 Cygnus Solutions.
Copyright 1996, 1997, 1998, 2000, 2001 Cygnus Solutions.
Written by Steve Chamberlain (sac@cygnus.com), Doug Evans (dje@cygnus.com),
Geoffrey Noer (noer@cygnus.com) of Cygnus Support.
@ -106,7 +106,10 @@ getrlimit (int resource, struct rlimit *rlp)
{
MEMORY_BASIC_INFORMATION m;
if (!rlp || !VirtualQuery (rlp, &m, sizeof (m)) || (m.State != MEM_COMMIT))
return EFAULT;
{
set_errno (EFAULT);
return -1;
}
rlp->rlim_cur = RLIM_INFINITY;
rlp->rlim_max = RLIM_INFINITY;
@ -139,7 +142,23 @@ setrlimit (int resource, const struct rlimit *rlp)
{
MEMORY_BASIC_INFORMATION m;
if (!rlp || !VirtualQuery (rlp, &m, sizeof (m)) || (m.State != MEM_COMMIT))
return EFAULT;
{
set_errno (EFAULT);
return -1;
}
struct rlimit oldlimits;
// Check if the request is to actually change the resource settings.
// If it does not result in a change, take no action and do not
// fail.
if (getrlimit(resource, &oldlimits) < 0)
return -1;
if (oldlimits.rlim_cur == rlp->rlim_cur &&
oldlimits.rlim_max == rlp->rlim_max)
// No change in resource requirements, succeed immediately
return 0;
switch (resource)
{