From 87c0d9c6a4f09b96b00ec4796f824dbcfab1ffb3 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 6 May 2025 12:06:56 +0200 Subject: FileDescriptor: add convenience wrapper for pidfd_open --- linuxnamespaces/filedescriptor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/linuxnamespaces/filedescriptor.py b/linuxnamespaces/filedescriptor.py index e4eff9b..2cf8442 100644 --- a/linuxnamespaces/filedescriptor.py +++ b/linuxnamespaces/filedescriptor.py @@ -41,6 +41,11 @@ class FileDescriptor(int): """Duplicate the file to the given file descriptor number.""" return FileDescriptor(os.dup2(self, fd2, inheritable)) + @classmethod + def pidfd_open(cls, pid: int, flags: int = 0) -> typing.Self: + """Convenience wrapper for os.pidfd_open.""" + return cls(os.pidfd_open(pid, flags)) + def fileno(self) -> int: """Return self such that it satisfies the HasFileno protocol.""" return self -- cgit v1.2.3