summaryrefslogtreecommitdiff
path: root/_dbus_bindings
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-05-18 10:49:00 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-05-18 10:49:00 +0100
commitc1f49ac473ac8910aa14f65362088a22e3f60a42 (patch)
tree1fefb252ece3263e98fa0646778b5fe391b59e00 /_dbus_bindings
parent630a7c54d85b36b82b1e180703d712ca2d5c5650 (diff)
UnixFd: don't close file descriptors passed to the constructor as an int
Elvis agreed that this shouldn't differ from our handling of objects with a fileno(). This means that _message_iter_get_pyobject does need to close the fd itself, so do that.
Diffstat (limited to '_dbus_bindings')
-rw-r--r--_dbus_bindings/message-get-args.c9
-rw-r--r--_dbus_bindings/unixfd.c13
2 files changed, 11 insertions, 11 deletions
diff --git a/_dbus_bindings/message-get-args.c b/_dbus_bindings/message-get-args.c
index 6e60a97..2155b3d 100644
--- a/_dbus_bindings/message-get-args.c
+++ b/_dbus_bindings/message-get-args.c
@@ -327,8 +327,13 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
DBG("%s", "found an unix fd");
dbus_message_iter_get_basic(iter, &u.fd);
args = Py_BuildValue("(i)", u.fd);
- if (!args) break;
- ret = PyObject_Call((PyObject *)&DBusPyUnixFd_Type, args, kwargs);
+ if (args) {
+ ret = PyObject_Call((PyObject *)&DBusPyUnixFd_Type, args,
+ kwargs);
+ }
+ if (u.fd >= 0) {
+ close(u.fd);
+ }
break;
#endif
diff --git a/_dbus_bindings/unixfd.c b/_dbus_bindings/unixfd.c
index 5390657..fa2f224 100644
--- a/_dbus_bindings/unixfd.c
+++ b/_dbus_bindings/unixfd.c
@@ -36,10 +36,8 @@ PyDoc_STRVAR(UnixFd_tp_doc,
"implements the fileno() method. Otherwise, `ValueError` will be\n"
"raised.\n"
"\n"
-"UnixFd keeps a dup() (duplicate) of the supplied file descriptor. If an integer\n"
-"value is supplied, UnixFd takes the ownership, and the original file descriptor\n"
-"\nis closed. If a file or socket object is supplied, the original fd is not closed\n"
-"and file descriptor ownership is shared between both.\n"
+"UnixFd keeps a dup() (duplicate) of the supplied file descriptor. The\n"
+"caller remains responsible for closing the original fd.\n"
"``variant_level`` must be non-negative; the default is 0.\n"
"\n"
":IVariables:\n"
@@ -84,9 +82,7 @@ UnixFd_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs UNUSED)
if (fd < 0) {
PyErr_Format(PyExc_ValueError, "Invalid file descriptor");
return NULL;
- }
- /* takes ownership of original fd */
- close(fd_original);
+ }
} else if (PyObject_HasAttrString(arg, "fileno")) {
fdnumber = PyObject_CallMethod(arg, "fileno", NULL);
@@ -106,8 +102,7 @@ UnixFd_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs UNUSED)
if (fd < 0) {
PyErr_Format(PyExc_ValueError, "Invalid file descriptor from fileno()");
return NULL;
- }
- /* does not close fd_original because we keep sharing ownership */
+ }
} else {
PyErr_Format(PyExc_ValueError, "Argument is not int and does not "