OSDN Git Service

* resource.cc (getrlimit): Set errno on EFAULT instead of returning it.
authorcorinna <corinna>
Fri, 5 Jan 2001 09:01:18 +0000 (09:01 +0000)
committercorinna <corinna>
Fri, 5 Jan 2001 09:01:18 +0000 (09:01 +0000)
        (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.

winsup/cygwin/ChangeLog
winsup/cygwin/resource.cc

index cc49165..87160a7 100644 (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.
index e8e53d1..cb1fc22 100644 (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)
     {