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()
# XXX - we don't support all scripts that vserver script does
self.__do_chcontext(state_file)
for cmd in self.INITSCRIPTS:
- try:
- # enter vserver context
- arg_subst = { 'runlevel': runlevel }
- cmd_args = [cmd[0]] + map(lambda x: x % arg_subst,
+ try:
+ # enter vserver context
+ arg_subst = { 'runlevel': runlevel }
+ cmd_args = [cmd[0]] + map(lambda x: x % arg_subst,
cmd[1:])
- print >>log, "executing '%s'" % " ".join(cmd_args)
- os.spawnvp(os.P_NOWAIT,cmd[0],cmd_args)
- except:
- print >>log, traceback.format_exc()
- os._exit(1)
+ if os.path.isfile(cmd[0]):
+ print >>log, "executing '%s'" % " ".join(cmd_args)
+ os.spawnvp(os.P_NOWAIT,cmd[0],cmd_args)
+ except:
+ print >>log, traceback.format_exc()
# we get here due to an exception in the top-level child process
except Exception, ex:
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,
pass
def init_disk_info(self):
+ try:
+ dlimit = vserver.getdlimit(self.dir, self.ctx)
+ self.disk_blocks = dlimit[0]
+ self.disk_inodes = dlimit[2]
+ return self.disk_blocks * 1024
+ except Exception, e:
+ pass
cmd = "/usr/sbin/vdu --script --space --inodes --blocksize 1024 --xid %d %s" % (self.ctx, self.dir)
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
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
+