use platform provided RLIMIT_ values
Marc Fiuczynski [Thu, 28 Jun 2007 21:35:20 +0000 (21:35 +0000)]
python/vserver.py
python/vserverimpl.c

index cf0b84e..6bddee1 100644 (file)
@@ -9,6 +9,7 @@ import signal
 import sys
 import time
 import traceback
+import resource
 
 import mountimpl
 import runcmd
@@ -19,16 +20,6 @@ import cpulimit, bwlimit
 from vserverimpl import VS_SCHED_CPU_GUARANTEED as SCHED_CPU_GUARANTEED
 from vserverimpl import DLIMIT_INF
 from vserverimpl import VC_LIM_KEEP
-
-from vserverimpl import RLIMIT_CPU
-from vserverimpl import RLIMIT_RSS
-from vserverimpl import RLIMIT_NPROC
-from vserverimpl import RLIMIT_NOFILE
-from vserverimpl import RLIMIT_MEMLOCK
-from vserverimpl import RLIMIT_AS
-from vserverimpl import RLIMIT_LOCKS
-from vserverimpl import RLIMIT_SIGPENDING
-from vserverimpl import RLIMIT_MSGQUEUE
 from vserverimpl import VLIMIT_NSOCK
 from vserverimpl import VLIMIT_OPENFD
 from vserverimpl import VLIMIT_ANON
@@ -46,19 +37,19 @@ FLAGS_HIDEINFO = 32
 FLAGS_ULIMIT = 64
 FLAGS_NAMESPACE = 128
 
-RLIMITS = {"CPU": RLIMIT_CPU,
-           "RSS": RLIMIT_RSS,
-           "NPROC": RLIMIT_NPROC,
-           "NOFILE": RLIMIT_NOFILE,
-           "MEMLOCK": RLIMIT_MEMLOCK,
-           "AS": RLIMIT_AS,
-           "LOCKS": RLIMIT_LOCKS,
-           "SIGPENDING": RLIMIT_SIGPENDING,
-           "MSGQUEUE": RLIMIT_MSGQUEUE,
-           "NSOCK": VLIMIT_NSOCK,
-           "OPENFD": VLIMIT_OPENFD,
-           "ANON": VLIMIT_ANON,
-           "SHMEM": VLIMIT_SHMEM}
+RLIMITS = { "NSOCK": VLIMIT_NSOCK,
+            "OPENFD": VLIMIT_OPENFD,
+            "ANON": VLIMIT_ANON,
+            "SHMEM": VLIMIT_SHMEM}
+
+# add in the platform supported rlimits
+for entry in resource.__dict__.keys():
+    if entry.find("RLIMIT_")==0:
+        k = entry[len("RLIMIT_"):]
+        if not RLIMITS.has_key(k):
+            RLIMITS[k]=resource.__dict__[entry]
+        else:
+            print "WARNING: duplicate RLIMITS key %s" % k
 
 class NoSuchVServer(Exception): pass
 
index 4afba2a..0bbd2c1 100644 (file)
@@ -340,17 +340,6 @@ initvserverimpl(void)
   PyModule_AddIntConstant(mod, "DLIMIT_INF", (int)CDLIM_INFINITY);
   PyModule_AddIntConstant(mod, "VC_LIM_KEEP", (int)VC_LIM_KEEP);
 
-  PyModule_AddIntConstant(mod, "RLIMIT_CPU", (int)RLIMIT_CPU);
-  PyModule_AddIntConstant(mod, "RLIMIT_RSS", (int)RLIMIT_RSS);
-  PyModule_AddIntConstant(mod, "RLIMIT_NPROC", (int)RLIMIT_NPROC);
-  PyModule_AddIntConstant(mod, "RLIMIT_NOFILE", (int)RLIMIT_NOFILE);
-  PyModule_AddIntConstant(mod, "RLIMIT_MEMLOCK", (int)RLIMIT_MEMLOCK);
-  PyModule_AddIntConstant(mod, "RLIMIT_AS", (int)RLIMIT_AS);
-  PyModule_AddIntConstant(mod, "RLIMIT_LOCKS", (int)RLIMIT_LOCKS);
-
-  PyModule_AddIntConstant(mod, "RLIMIT_SIGPENDING", (int)RLIMIT_SIGPENDING);
-  PyModule_AddIntConstant(mod, "RLIMIT_MSGQUEUE", (int)RLIMIT_MSGQUEUE);
-
   PyModule_AddIntConstant(mod, "VLIMIT_NSOCK", (int)VLIMIT_NSOCK);
   PyModule_AddIntConstant(mod, "VLIMIT_OPENFD", (int)VLIMIT_OPENFD);
   PyModule_AddIntConstant(mod, "VLIMIT_ANON", (int)VLIMIT_ANON);