diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2001-01-05 09:01:18 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2001-01-05 09:01:18 +0000 |
commit | f3236259b4201a09781c1119684170f379299033 (patch) | |
tree | a6cc3f18ee8a338445cbd79305007f3230f688a2 /winsup/cygwin/resource.cc | |
parent | a5e570bcc361f46665e3499ffa781f9480862a77 (diff) | |
download | cygnal-f3236259b4201a09781c1119684170f379299033.tar.gz cygnal-f3236259b4201a09781c1119684170f379299033.tar.bz2 cygnal-f3236259b4201a09781c1119684170f379299033.zip |
* 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.
Diffstat (limited to 'winsup/cygwin/resource.cc')
-rw-r--r-- | winsup/cygwin/resource.cc | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/winsup/cygwin/resource.cc b/winsup/cygwin/resource.cc index e8e53d110..cb1fc222a 100644 --- a/winsup/cygwin/resource.cc +++ b/winsup/cygwin/resource.cc @@ -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) { |