back ported setsched syscall for new scheduler
[util-vserver.git] / python / vserver.py
index cc568d2..64cc681 100644 (file)
@@ -8,9 +8,10 @@ import sys
 import time
 import traceback
 
-#import mount
+import mountimpl
 import linuxcaps
 import passfdimpl
+import utmp
 import vserverimpl
 
 from util_vserver_vars import *
@@ -164,12 +165,27 @@ class VServer:
         garbage += filter(os.path.isfile, map((LOCKDIR + "/").__add__,
                                               os.listdir(LOCKDIR)))
         for f in garbage:
-            print >>log, "removing " + f
             os.unlink(f)
 
         # set the initial runlevel
+        f = open(RUNDIR + "/utmp", "w")
+        utmp.set_runlevel(f, runlevel)
+        f.close()
 
         # mount /proc and /dev/pts
+        self.__do_mount("none", "/proc", "proc")
+        # XXX - magic mount options
+        self.__do_mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=0620")
+
+    def __do_mount(self, *mount_args):
+
+        try:
+            mountimpl.mount(*mount_args)
+        except OSError, ex:
+            if ex.errno == errno.EBUSY:
+                # assume already mounted
+                return
+            raise ex
 
     def enter(self):
 
@@ -177,7 +193,7 @@ class VServer:
         self.__do_chroot()
         self.__do_chcontext(state_file)
 
-    def start(self, runlevel = 3):
+    def start(self, wait, runlevel = 3):
 
         child_pid = os.fork()
         if child_pid == 0:
@@ -207,18 +223,19 @@ class VServer:
                 # XXX - we don't support all scripts that vserver script does
                 cmd_pid = 0
                 for cmd in self.INITSCRIPTS + [None]:
-                    # don't bother waiting for last command to terminate
-                    if cmd == None:
-                        os._exit(0)
-
-                    # wait for previous command to terminate
-                    if cmd_pid:
+                    # wait for previous command to terminate, unless it
+                    # is the last one and the caller has specified to wait
+                    if cmd_pid and (cmd != None or wait):
                         try:
                             os.waitpid(cmd_pid, 0)
                         except:
                             print >>log, "error waiting for %s:" % cmd_pid
                             traceback.print_exc()
 
+                    # end of list
+                    if cmd == None:
+                        os._exit(0)
+
                     # fork and exec next command
                     cmd_pid = os.fork()
                     if cmd_pid == 0: