Don't wait for the initscripts to complete.
[util-vserver.git] / python / vserver.py
index 5c32676..de8c164 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 2005 Princeton University
 
-#$Id: vserver.py,v 1.70 2007/08/01 21:48:42 dhozac Exp $
+#$Id: vserver.py,v 1.72 2007/08/02 16:01:59 dhozac Exp $
 
 import errno
 import fcntl
@@ -14,9 +14,6 @@ import traceback
 import subprocess
 import resource
 
-import mountimpl
-import runcmd
-import utmp
 import vserverimpl
 import cpulimit, bwlimit
 
@@ -128,7 +125,7 @@ class VServerConfig:
                       os.access(full_name, os.R_OK)):
                     f = open(full_name, "r")
                     cache[full_name.replace(os.path.join(self.dir, ''),
-                                            '')] = f.readline().rstrip()
+                                            '')] = f.read().rstrip()
                     f.close()
         os.path.walk(self.dir, add_to_cache, self.cache)
 
@@ -205,9 +202,6 @@ class VServer:
         minimum = int(self.config.get("rlimits/%s.min"%type.lower(),VC_LIM_KEEP))
         return (hard,soft,minimum)
 
-    def set_WHITELISTED_config(self,whitelisted):
-        self.config.update('whitelisted', whitelisted)
-
     def set_capabilities(self, capabilities):
         return vserverimpl.setbcaps(self.ctx, vserverimpl.text2bcaps(capabilities))
 
@@ -399,18 +393,18 @@ class VServer:
 
         # set the initial runlevel
         f = open(RUNDIR + "/utmp", "w")
-        utmp.set_runlevel(f, runlevel)
+        vserverimpl.setrunlevel(f, runlevel)
         f.close()
 
         # mount /proc and /dev/pts
-        self.__do_mount("none", "/proc", "proc")
+        self.__do_mount("none", self.dir, "/proc", "proc")
         # XXX - magic mount options
-        self.__do_mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=0620")
+        self.__do_mount("none", self.dir, "/dev/pts", "devpts", 0, "gid=5,mode=0620")
 
     def __do_mount(self, *mount_args):
 
         try:
-            mountimpl.mount(*mount_args)
+            vserverimpl.mount(*mount_args)
         except OSError, ex:
             if ex.errno == errno.EBUSY:
                 # assume already mounted
@@ -462,7 +456,7 @@ class VServer:
                          cmd_args = [cmd[0]] + map(lambda x: x % arg_subst,
                                                    cmd[1:])
                          print >>log, "executing '%s'" % " ".join(cmd_args)
-                         os.spawnvp(os.P_WAIT,cmd[0],cmd_args)
+                         os.spawnvp(os.P_NOWAIT,cmd[0],cmd_args)
                      except:
                          traceback.print_exc()
                          os._exit(1)
@@ -511,10 +505,17 @@ class VServer:
 
 def create(vm_name, static = False, ctor = VServer):
 
-    options = []
+    options = ['vuseradd']
     if static:
         options += ['--static']
-    runcmd.run('vuseradd', options + [vm_name])
+    ret = os.spawnvp(os.P_WAIT, 'vuseradd', options + [vm_name])
+    if !os.WIFEXITED(ret) || os.WEXITSTATUS(ret) != 0:
+        out = "system command ('%s') " % options
+        if os.WIFEXITED(ret):
+            out += "failed, rc = %d" % os.WEXITSTATUS(ret)
+        else:
+            out += "killed by signal %d" % os.WTERMSIG(ret)
+        raise SystemError, out
     vm_id = pwd.getpwnam(vm_name)[2]
 
     return ctor(vm_name, vm_id)