summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2025-05-06 12:06:56 +0200
committerHelmut Grohne <helmut@subdivi.de>2025-05-06 12:06:56 +0200
commit87c0d9c6a4f09b96b00ec4796f824dbcfab1ffb3 (patch)
treebf71f0943f15f5f318b993b170a6c73ce61328dd
parent1fa71c54e688b10c8c70dfb3cf7136cfb22f2085 (diff)
downloadpython-linuxnamespaces-87c0d9c6a4f09b96b00ec4796f824dbcfab1ffb3.tar.gz
FileDescriptor: add convenience wrapper for pidfd_openHEADmain
-rw-r--r--linuxnamespaces/filedescriptor.py5
1 files changed, 5 insertions, 0 deletions
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