[Python-checkins] r80914 - in python/branches/signalfd-issue8407: Lib/test/test_signal.py Modules/signalmodule.c
jean-paul.calderone
python-checkins at python.org
Fri May 7 09:30:50 CEST 2010
Author: jean-paul.calderone
Date: Fri May 7 09:30:50 2010
New Revision: 80914
Log:
Implement flags parameter to signalfd
Modified:
python/branches/signalfd-issue8407/Lib/test/test_signal.py
python/branches/signalfd-issue8407/Modules/signalmodule.c
Modified: python/branches/signalfd-issue8407/Lib/test/test_signal.py
==============================================================================
--- python/branches/signalfd-issue8407/Lib/test/test_signal.py (original)
+++ python/branches/signalfd-issue8407/Lib/test/test_signal.py Fri May 7 09:30:50 2010
@@ -557,6 +557,43 @@
self.assertTrue(bytes)
+ def test_close_on_exec(self):
+ """If the bit mask passed as the 3rd argument to signalfd includes
+ SFD_CLOEXEC, the returned file descriptor has FD_CLOEXEC set on it.
+ """
+ import fcntl
+ fd = signal.signalfd(-1, [], signal.SFD_CLOEXEC)
+ self.addCleanup(os.close, fd)
+ flags = fcntl.fcntl(fd, fcntl.F_GETFD)
+ self.assertTrue(flags & fcntl.FD_CLOEXEC)
+
+
+ def test_nonblocking(self):
+ """If the bit mask passed as the 3rd argument to signalfd includes
+ SFD_NOBLOCK, the file description referenced by the returned file
+ descriptor has O_NONBLOCK set on it.
+ """
+ import fcntl
+ fd = signal.signalfd(-1, [], signal.SFD_NONBLOCK)
+ self.addCleanup(os.close, fd)
+ flags = fcntl.fcntl(fd, fcntl.F_GETFL)
+ self.assertTrue(flags & os.O_NONBLOCK)
+
+
+ def test_default_flags(self):
+ """If an empty bit mask is passed as the 3rd argument to signalfd,
+ neither FD_CLOEXEC nor O_NONBLOCK is set on the resulting file
+ descriptor/description.
+ """
+ import fcntl
+ fd = signal.signalfd(-1, [])
+ self.addCleanup(os.close, fd)
+ flags = fcntl.fcntl(fd, fcntl.F_GETFD)
+ self.assertFalse(flags & fcntl.FD_CLOEXEC)
+ flags = fcntl.fcntl(fd, fcntl.F_GETFL)
+ self.assertFalse(flags & os.O_NONBLOCK)
+
+
def test_main():
test_support.run_unittest(
BasicSignalTests, InterProcessSignalTests,
Modified: python/branches/signalfd-issue8407/Modules/signalmodule.c
==============================================================================
--- python/branches/signalfd-issue8407/Modules/signalmodule.c (original)
+++ python/branches/signalfd-issue8407/Modules/signalmodule.c Fri May 7 09:30:50 2010
@@ -569,13 +569,13 @@
static PyObject *
signal_signalfd(PyObject *self, PyObject *args)
{
- int result;
+ int result, flags = 0;
sigset_t mask;
int fd;
PyObject *signals;
- if (!PyArg_ParseTuple(args, "iO:signalfd", &fd, &signals)) {
+ if (!PyArg_ParseTuple(args, "iO|i:signalfd", &fd, &signals, &flags)) {
return NULL;
}
@@ -583,7 +583,7 @@
return NULL;
}
- result = signalfd(-1, &mask, 0);
+ result = signalfd(-1, &mask, flags);
if (result == -1) {
PyErr_SetFromErrno(PyExc_OSError);
More information about the Python-checkins
mailing list