From a0cc21f8bb6752ffe0ee5f4f5b575dc50d6d46ae Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 22 Apr 2009 03:41:05 +0200 Subject: unix-fd: add message encoding/decoding for unix fds When appending unix fds to the message a new entry in the fd array will be allocated and the index to it will be written to the message payload. When parsing unix fds from the message the index will be read from the payload and then looked up in the fd array. When we read fds we put them in a queue first. Since each message knows how many fds are attached to it we will then pop enough fds from this queue each time we decode a message from the stream. This should make sending and receiving more portable since we don't make any strong requirements on the exact semantics of the SCM_RIGHTS implementation: as long as fds are recieved in order, none or lost and the arrive at the same time as at least one byte from the actual message dat we should be able to handle them correctly. --- dbus/dbus-message-private.h | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'dbus/dbus-message-private.h') diff --git a/dbus/dbus-message-private.h b/dbus/dbus-message-private.h index c1e368f7..1e8b107a 100644 --- a/dbus/dbus-message-private.h +++ b/dbus/dbus-message-private.h @@ -23,6 +23,8 @@ #ifndef DBUS_MESSAGE_PRIVATE_H #define DBUS_MESSAGE_PRIVATE_H +#include + #include #include #include @@ -66,12 +68,21 @@ struct DBusMessageLoader DBusList *messages; /**< Complete messages. */ long max_message_size; /**< Maximum size of a message */ + long max_message_unix_fds; /**< Maximum unix fds in a message */ - unsigned int buffer_outstanding : 1; /**< Someone is using the buffer to read */ + DBusValidity corruption_reason; /**< why we were corrupted */ unsigned int corrupted : 1; /**< We got broken data, and are no longer working */ - DBusValidity corruption_reason; /**< why we were corrupted */ + unsigned int buffer_outstanding : 1; /**< Someone is using the buffer to read */ + +#ifdef HAVE_UNIX_FD_PASSING + unsigned int unix_fds_outstanding : 1; /**< Someone is using the unix fd array to read */ + + int *unix_fds; /**< File descriptors that have been read from the transport but not yet been handed to any message. Array will be allocated at first use. */ + unsigned n_unix_fds_allocated; /**< Number of file descriptors this array has space for */ + unsigned n_unix_fds; /**< Number of valid file descriptors in array */ +#endif }; @@ -100,7 +111,7 @@ struct DBusMessage #ifndef DBUS_DISABLE_CHECKS unsigned int in_cache : 1; /**< Has been "freed" since it's in the cache (this is a debug feature) */ #endif - + DBusList *size_counters; /**< 0-N DBusCounter used to track message size. */ long size_counter_delta; /**< Size we incremented the size counters by. */ @@ -111,6 +122,15 @@ struct DBusMessage #ifndef DBUS_DISABLE_CHECKS int generation; /**< _dbus_current_generation when message was created */ #endif + +#ifdef HAVE_UNIX_FD_PASSING + int *unix_fds; + /**< Unix file descriptors associated with this message. These are + closed when the message is destroyed, hence make sure to dup() + them when adding or removing them here. */ + unsigned n_unix_fds; /**< Number of valid fds in the array */ + unsigned n_unix_fds_allocated; /**< Allocated size of the array */ +#endif }; dbus_bool_t _dbus_message_iter_get_args_valist (DBusMessageIter *iter, @@ -118,6 +138,9 @@ dbus_bool_t _dbus_message_iter_get_args_valist (DBusMessageIter *iter, int first_arg_type, va_list var_args); + +void _dbus_check_fdleaks(void); + /** @} */ DBUS_END_DECLS -- cgit From bfad32422f1f78bce4de1e88a4afb5cc295bb877 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 20 May 2009 01:32:46 +0200 Subject: unix-fd: add logic to count unix fds the same way as allocated memory This make all counters count both bytes of memory and unix fds. --- dbus/dbus-message-private.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'dbus/dbus-message-private.h') diff --git a/dbus/dbus-message-private.h b/dbus/dbus-message-private.h index 1e8b107a..03257a9b 100644 --- a/dbus/dbus-message-private.h +++ b/dbus/dbus-message-private.h @@ -112,7 +112,7 @@ struct DBusMessage unsigned int in_cache : 1; /**< Has been "freed" since it's in the cache (this is a debug feature) */ #endif - DBusList *size_counters; /**< 0-N DBusCounter used to track message size. */ + DBusList *counters; /**< 0-N DBusCounter used to track message size/unix fds. */ long size_counter_delta; /**< Size we incremented the size counters by. */ dbus_uint32_t changed_stamp : CHANGED_STAMP_BITS; /**< Incremented when iterators are invalidated. */ @@ -130,6 +130,8 @@ struct DBusMessage them when adding or removing them here. */ unsigned n_unix_fds; /**< Number of valid fds in the array */ unsigned n_unix_fds_allocated; /**< Allocated size of the array */ + + long unix_fd_counter_delta; /**< Size we incremented the unix fd counter by */ #endif }; -- cgit