summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_signal.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2019-11-20 04:39:14 (GMT)
committerGitHub <noreply@github.com>2019-11-20 04:39:14 (GMT)
commit7483451577916e693af6d20cf520b2cc7e2174d2 (patch)
tree54fdd671a4513a4cf938f1438ce53823909b02db /Lib/test/test_signal.py
parentbe143ec99674ba38c5811f34cdb85ef39c2dc8f8 (diff)
downloadcpython-7483451577916e693af6d20cf520b2cc7e2174d2.zip
cpython-7483451577916e693af6d20cf520b2cc7e2174d2.tar.gz
cpython-7483451577916e693af6d20cf520b2cc7e2174d2.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_signal.py')
-rw-r--r--Lib/test/test_signal.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index d41e94b..119e9e0 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -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()