X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=python%2Fvserver.py;h=33c195298ba93dcf54da359f290f21adc7f1365c;hb=fa5203af07158455a1c35c311ec69c23c7702d2f;hp=e3748f4accfd4a845115680505058dbb52242d25;hpb=c691247edc297fa51265d333950b2004d8b357fc;p=util-vserver-pl.git diff --git a/python/vserver.py b/python/vserver.py index e3748f4..33c1952 100644 --- a/python/vserver.py +++ b/python/vserver.py @@ -267,7 +267,6 @@ class VServer: block_usage = self.disk_blocks inode_usage = self.disk_inodes - try: vserverimpl.setdlimit(self.dir, self.ctx, @@ -396,13 +395,18 @@ class VServer: 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() @@ -447,9 +451,6 @@ class VServer: 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, @@ -506,3 +507,12 @@ def create(vm_name, static = False, ctor = VServer): 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 +