mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
closes bpo-38712: Add signal.pidfd_send_signal. (GH-17070)
This exposes a Linux-specific syscall for sending a signal to a process identified by a file descriptor rather than a pid. For simplicity, we don't support the siginfo_t parameter to the syscall. This parameter allows implementing a pidfd version of rt_sigqueueinfo(2), which Python also doesn't support.
This commit is contained in:
parent
be143ec996
commit
7483451577
6 changed files with 153 additions and 1 deletions
|
@ -1273,6 +1273,25 @@ class RaiseSignalTest(unittest.TestCase):
|
|||
self.assertTrue(is_ok)
|
||||
|
||||
|
||||
class PidfdSignalTest(unittest.TestCase):
|
||||
|
||||
@unittest.skipUnless(
|
||||
hasattr(signal, "pidfd_send_signal"),
|
||||
"pidfd support not built in",
|
||||
)
|
||||
def test_pidfd_send_signal(self):
|
||||
with self.assertRaises(OSError) as cm:
|
||||
signal.pidfd_send_signal(0, signal.SIGINT)
|
||||
if cm.exception.errno == errno.ENOSYS:
|
||||
self.skipTest("kernel does not support pidfds")
|
||||
self.assertEqual(cm.exception.errno, errno.EBADF)
|
||||
my_pidfd = os.open(f'/proc/{os.getpid()}', os.O_DIRECTORY)
|
||||
self.addCleanup(os.close, my_pidfd)
|
||||
with self.assertRaisesRegexp(TypeError, "^siginfo must be None$"):
|
||||
signal.pidfd_send_signal(my_pidfd, signal.SIGINT, object(), 0)
|
||||
with self.assertRaises(KeyboardInterrupt):
|
||||
signal.pidfd_send_signal(my_pidfd, signal.SIGINT)
|
||||
|
||||
def tearDownModule():
|
||||
support.reap_children()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue