From f05f87a825ab8ed5273674a7f65521ffc526f0d2 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 15 Mar 2003 06:00:01 +0000 Subject: 2003-03-15 Havoc Pennington * bus/dispatch.c (bus_dispatch_test): OK, now finally actually write useful test code, after all that futzing around ;-) Test does not yet pass because we can't handle OOM in _dbus_transport_messages_pending (basically, dbus_connection_preallocate_send() does not prealloc the write watch). To fix this, I think we need to add new stuff to set_watch_functions, namely a SetEnabled function so we can alloc the watch earlier, then enable it later. * dbus/Makefile.am (libdbus_convenience_la_SOURCES): move dbus-memory.c to the convenience lib * bus/test.c: rename some static functions to keep them clearly distinct from stuff in connection.c. Handle client disconnection. --- dbus/Makefile.am | 2 +- dbus/dbus-memory.c | 6 ++++++ dbus/dbus-mempool.c | 5 ++++- dbus/dbus-message.c | 8 +++++++- dbus/dbus-sysdeps.c | 34 ++++++++++++++++++++++++++++++++++ dbus/dbus-sysdeps.h | 2 ++ dbus/dbus-transport-unix.c | 16 ++++++++++++++++ 7 files changed, 70 insertions(+), 3 deletions(-) (limited to 'dbus') diff --git a/dbus/Makefile.am b/dbus/Makefile.am index e9b08d13..c66c5367 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -34,7 +34,6 @@ libdbus_1_la_SOURCES= \ dbus-errors.c \ dbus-keyring.c \ dbus-keyring.h \ - dbus-memory.c \ dbus-message.c \ dbus-message-handler.c \ dbus-message-internal.h \ @@ -88,6 +87,7 @@ libdbus_convenience_la_SOURCES= \ dbus-list.h \ dbus-marshal.c \ dbus-marshal.h \ + dbus-memory.c \ dbus-mempool.c \ dbus-mempool.h \ dbus-message-builder.c \ diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index 83d17e6c..e1075228 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -256,6 +256,8 @@ dbus_malloc (size_t bytes) { if (fail_counts != -1) _dbus_set_fail_alloc_counter (fail_counts); + + _dbus_verbose (" FAILING malloc of %d bytes\n", bytes); return NULL; } @@ -297,6 +299,8 @@ dbus_malloc0 (size_t bytes) { if (fail_counts != -1) _dbus_set_fail_alloc_counter (fail_counts); + + _dbus_verbose (" FAILING malloc0 of %d bytes\n", bytes); return NULL; } @@ -340,6 +344,8 @@ dbus_realloc (void *memory, { if (fail_counts != -1) _dbus_set_fail_alloc_counter (fail_counts); + + _dbus_verbose (" FAILING realloc of %d bytes\n", bytes); return NULL; } diff --git a/dbus/dbus-mempool.c b/dbus/dbus-mempool.c index 2fde2568..9a0f6188 100644 --- a/dbus/dbus-mempool.c +++ b/dbus/dbus-mempool.c @@ -203,7 +203,10 @@ void* _dbus_mem_pool_alloc (DBusMemPool *pool) { if (_dbus_decrement_fail_alloc_counter ()) - return NULL; + { + _dbus_verbose (" FAILING mempool alloc\n"); + return NULL; + } if (pool->free_elements) { diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index b1fc6483..fe032dff 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -628,8 +628,10 @@ _dbus_message_add_size_counter (DBusMessage *message, _dbus_string_get_length (&message->header) + _dbus_string_get_length (&message->body); +#if 0 _dbus_verbose ("message has size %ld\n", message->size_counter_delta); +#endif _dbus_counter_adjust (message->size_counter, message->size_counter_delta); } @@ -2587,13 +2589,15 @@ decode_header_data (const DBusString *data, } fields[FIELD_SERVICE].offset = _DBUS_ALIGN_VALUE (pos + 1, 4); +#if 0 _dbus_verbose ("Found service name at offset %d\n", fields[FIELD_SERVICE].offset); +#endif break; case DBUS_HEADER_FIELD_NAME_AS_UINT32: if (fields[FIELD_NAME].offset >= 0) - { + { _dbus_verbose ("%s field provided twice\n", DBUS_HEADER_FIELD_NAME); return FALSE; @@ -2601,8 +2605,10 @@ decode_header_data (const DBusString *data, fields[FIELD_NAME].offset = _DBUS_ALIGN_VALUE (pos + 1, 4); +#if 0 _dbus_verbose ("Found message name at offset %d\n", fields[FIELD_NAME].offset); +#endif break; case DBUS_HEADER_FIELD_SENDER_AS_UINT32: if (fields[FIELD_SENDER].offset >= 0) diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index 7117e8fb..e6e0b276 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -50,6 +50,10 @@ #ifdef HAVE_POLL #include #endif +#ifdef HAVE_BACKTRACE +#include +#endif + #ifndef O_BINARY #define O_BINARY 0 @@ -2827,5 +2831,35 @@ _dbus_close (int fd, return TRUE; } +/** + * On GNU libc systems, print a crude backtrace to the verbose log. + * On other systems, print "no backtrace support" + * + */ +void +_dbus_print_backtrace (void) +{ +#if defined (HAVE_BACKTRACE) && defined (DBUS_ENABLE_VERBOSE_MODE) + void *bt[500]; + int bt_size; + int i; + char **syms; + + bt_size = backtrace (bt, 500); + + syms = backtrace_symbols (bt, bt_size); + + i = 0; + while (i < bt_size) + { + _dbus_verbose (" %s\n", syms[i]); + ++i; + } + + free (syms); +#else + _dbus_verbose (" D-BUS not compiled with backtrace support\n"); +#endif +} /** @} end of sysdeps */ diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 8cd62207..0c24d0c5 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -205,6 +205,8 @@ dbus_bool_t _dbus_full_duplex_pipe (int *fd1, dbus_bool_t _dbus_close (int fd, DBusError *error); +void _dbus_print_backtrace (void); + DBUS_END_DECLS; #endif /* DBUS_SYSDEPS_H */ diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c index dfaeb1ad..3c5fe848 100644 --- a/dbus/dbus-transport-unix.c +++ b/dbus/dbus-transport-unix.c @@ -164,8 +164,10 @@ check_write_watch (DBusTransport *transport) } else { +#if 0 _dbus_verbose ("Write watch is unchanged from %p on fd %d\n", unix_transport->write_watch, unix_transport->fd); +#endif } out: @@ -190,8 +192,10 @@ check_read_watch (DBusTransport *transport) need_read_watch = transport->receive_credentials_pending || _dbus_auth_do_work (transport->auth) == DBUS_AUTH_STATE_WAITING_FOR_INPUT; +#if 0 _dbus_verbose ("need_read_watch = %d authenticated = %d\n", need_read_watch, _dbus_transport_get_is_authenticated (transport)); +#endif if (transport->disconnected) need_read_watch = FALSE; @@ -232,8 +236,10 @@ check_read_watch (DBusTransport *transport) } else { +#if 0 _dbus_verbose ("Read watch is unchanged from %p on fd %d\n", unix_transport->read_watch, unix_transport->fd); +#endif } out: @@ -621,7 +627,9 @@ do_writing (DBusTransport *transport) _dbus_assert (message != NULL); _dbus_message_lock (message); +#if 0 _dbus_verbose ("writing message %p\n", message); +#endif _dbus_message_get_network_data (message, &header, &body); @@ -647,8 +655,10 @@ do_writing (DBusTransport *transport) total_bytes_to_write = _dbus_string_get_length (&unix_transport->encoded_message); +#if 0 _dbus_verbose ("encoded message is %d bytes\n", total_bytes_to_write); +#endif bytes_written = _dbus_write (unix_transport->fd, @@ -660,8 +670,10 @@ do_writing (DBusTransport *transport) { total_bytes_to_write = header_len + body_len; +#if 0 _dbus_verbose ("message is %d bytes\n", total_bytes_to_write); +#endif if (unix_transport->message_bytes_written < header_len) { @@ -868,14 +880,18 @@ unix_handle_watch (DBusTransport *transport, if (watch == unix_transport->read_watch && (flags & DBUS_WATCH_READABLE)) { +#if 0 _dbus_verbose ("handling read watch\n"); +#endif do_authentication (transport, TRUE, FALSE); do_reading (transport); } else if (watch == unix_transport->write_watch && (flags & DBUS_WATCH_WRITABLE)) { +#if 0 _dbus_verbose ("handling write watch\n"); +#endif do_authentication (transport, FALSE, TRUE); do_writing (transport); } -- cgit