block_usage = self.disk_blocks
inode_usage = self.disk_inodes
-
try:
vserverimpl.setdlimit(self.dir,
self.ctx,
self.__do_chroot()
self.__do_chcontext(None)
- def start(self, wait, runlevel = 3):
- self.vm_running = True
+ def start(self, runlevel = 3):
- child_pid = os.fork()
- if child_pid == 0:
+ if (os.fork() != 0):
+ # Parent should just return.
+ self.vm_running = True
+ return
+ else:
# child process
try:
+ # so we don't chcontext with priv'ed fds
+ close_nonstandard_fds()
+
# get a new session
os.setsid()
self.log(traceback.format_exc())
os._exit(0)
- # parent process
- return child_pid
-
def set_resources(self):
""" Called when vserver context is entered for first time,
vm_id = pwd.getpwnam(vm_name)[2]
return ctor(vm_name, vm_id)
+
+
+def close_nonstandard_fds():
+ """Close all open file descriptors other than 0, 1, and 2."""
+ _SC_OPEN_MAX = 4
+ for fd in range(3, os.sysconf(_SC_OPEN_MAX)):
+ try: os.close(fd)
+ except OSError: pass # most likely an fd that isn't open
+