Log error as well.
[util-vserver-pl.git] / python / vserver.py
index 081fd8a..569b979 100644 (file)
@@ -136,15 +136,15 @@ def adjust_lim(goal, curr):
     soft = curr[0]
     hard = curr[1]
     if gm != VC_LIM_KEEP:
-        if gm > soft:
+        if gm > soft or gm == resource.RLIM_INFINITY:
             soft = gm
-        if gm > hard:
+        if gm > hard or gm == resource.RLIM_INFINITY:
             hard = gm
     if gs != VC_LIM_KEEP:
-        if gs > soft:
+        if gs > soft or gs == resource.RLIM_INFINITY:
             soft = gs
     if gh != VC_LIM_KEEP:
-        if gh > hard:
+        if gh > hard or gh == resource.RLIM_INFINITY:
             hard = gh
     return (soft, hard)
 
@@ -201,9 +201,10 @@ class VServer:
             resource_type = RLIMITS[type]
             try:
                 vserverimpl.setrlimit(self.ctx, resource_type, hard, soft, min)
-                lim = resource.getrlimit(resource_type)
-                lim = adjust_lim((hard, soft, min), lim)
-                resource.setrlimit(resource_type, lim)
+                if hasattr(resource, 'RLIMIT_' + type):
+                    lim = resource.getrlimit(resource_type)
+                    lim = adjust_lim((hard, soft, min), lim)
+                    resource.setrlimit(resource_type, lim)
             except OSError, e:
                 self.log("Error: setrlimit(%d, %s, %d, %d, %d): %s"
                          % (self.ctx, type.lower(), hard, soft, min))
@@ -320,7 +321,7 @@ class VServer:
                                   vserverimpl.DLIMIT_INF,  # inode limit
                                   2)   # %age reserved for root
         except OSError, e:
-            self.log("Unexpected error with setdlimit for context %d" % self.ctx)
+            self.log("Unexpected error with setdlimit for context %d: %s" % (self.ctx, e))
 
 
         self.config.update('dlimits/0/space_total', block_limit)