11#!/usr/bin/env python3
22
3- '''
3+ """
44nsenter - run program with namespaces of other processes
5- '''
5+ """
66
77import argparse
88import ctypes
1717
1818libc = ctypes .CDLL ('libc.so.6' )
1919
20- def nsfd (process :str , ns_type :str ) -> Path :
20+
21+ def nsfd (process : str , ns_type : str ) -> Path :
2122 """
2223 Returns the namespace file descriptor for process (self or PID) and namespace type
2324 """
@@ -29,9 +30,9 @@ def __init__(self, pid: str, ns_type: str):
2930 self .pid = pid
3031 self .ns_type = ns_type
3132 self .parent_fd = nsfd ('self' , ns_type ).open ()
32- self .parent_fileno = self .parent_fd .fileno ()
33+ self .parent_fileno = self .parent_fd .fileno ()
3334 self .target_fd = nsfd (pid , ns_type ).open ()
34- self .target_fileno = self .target_fd .fileno ()
35+ self .target_fileno = self .target_fd .fileno ()
3536
3637 def __enter__ (self ):
3738 log .debug ('Entering %s namespace %s' , self .ns_type , self .pid )
@@ -46,9 +47,11 @@ def __exit__(self, type, value, tb):
4647 pass
4748 self .parent_fd .close ()
4849
50+
4951def main ():
5052 parser = argparse .ArgumentParser (description = __doc__ )
51- parser .add_argument ('--target' , '-t' , required = True , metavar = 'PID' , help = 'Specify a target process to get contexts from.' )
53+ parser .add_argument ('--target' , '-t' , required = True , metavar = 'PID' ,
54+ help = 'Specify a target process to get contexts from.' )
5255 for ns in NAMESPACE_NAMES :
5356 parser .add_argument ('--{}' .format (ns ), action = 'store_true' , help = 'Enter the {} namespace' .format (ns ))
5457 parser .add_argument ('--all' , action = 'store_true' , help = 'Enter all namespaces' )
0 commit comments