Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

Commit 2a8a55c

Browse files
committed
support pid as int
1 parent e2e030e commit 2a8a55c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

nsenter/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def nsfd(process:str, ns_type:str) -> Path:
2323
"""
2424
Returns the namespace file descriptor for process (self or PID) and namespace type
2525
"""
26-
return Path('/proc') / process / 'ns' / ns_type
26+
return Path('/proc') / str(process) / 'ns' / ns_type
2727

2828

2929
class Namespace:
@@ -42,14 +42,19 @@ def __enter__(self):
4242
def __exit__(self, type, value, tb):
4343
log.debug('Leaving %s namespace %s', self.ns_type, self.pid)
4444
libc.setns(self.parent_fileno, 0)
45+
try:
46+
self.target_fd.close()
47+
except:
48+
pass
49+
self.parent_fd.close()
4550

4651
def main():
4752
parser = argparse.ArgumentParser(description=__doc__)
48-
parser.add_argument('--target', metavar='PID', help='Specify a target process to get contexts from.')
53+
parser.add_argument('--target', required=True, metavar='PID', help='Specify a target process to get contexts from.')
4954
for ns in NAMESPACE_NAMES:
5055
parser.add_argument('--{}'.format(ns), action='store_true', help='Enter the {} namespace'.format(ns))
5156
parser.add_argument('--all', action='store_true', help='Enter all namespaces')
52-
parser.add_argument('command', nargs='*', default='/bin/sh')
57+
parser.add_argument('command', nargs='*', default=['/bin/sh'])
5358

5459
args = parser.parse_args()
5560

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def read(fname):
1212
def setup_package():
1313
setuptools.setup(
1414
name='nsenter',
15-
version='0.1.1',
15+
version='0.1.2',
1616
url='https://github.com/zalando/python-nsenter',
1717
description='Enter kernel namespaces from Python',
1818
author='Henning Jacobs',

0 commit comments

Comments
 (0)