Child process ID
Elbert-Tardis opened this issue · 4 comments
Hi!
I'm using the SplitExec class (or actually pychroot.Chroot does) to setup a jail. To do this i've subclassed pychroot.Chroot and overruled the _parent_setup() method, which is called from the __enter__() method as shown below.
What i need to do is setup a pair of veth interfaces and move one of them to the network namespace of the jail. I want to do this based upon the process ID. Something like:
ip link add veth0 type veth peer name veth1
ip link set veth0 netns <process ID>
However, the childpid attribute is set right after the call to _parent_setup() so i cannot use it from this method. Is there a reason why the childpid attribute is initialized after the call? Or would it be possible to swap the two statements?
Kind regards,
Elbert
def __enter__(self):
parent_pipe, child_pipe = Pipe()
childpid = os.fork()
if childpid != 0:
==> self._parent_setup()
==> self.childpid = childpid
No, there's no reason I can think of for that ordering, probably just got overlooked.
Thanks a lot!
I tossed out a 0.8.2 release for you that has this fix.
Once again: Thank you very much!
Kind regards,
Elbert