From 3e589736d2411cb76ac1dc414e8a132670e98b6d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 12 May 2015 11:28:36 +0100 Subject: [PATCH 3/5] _dbus_server_init_base: raise a DBusError This can currently only fail from OOM, but I'm about to make it possible to fail from insufficient entropy. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90414 --- dbus/dbus-server-debug-pipe.c | 10 ++++++---- dbus/dbus-server-protected.h | 3 ++- dbus/dbus-server-socket.c | 3 ++- dbus/dbus-server.c | 21 +++++++++++++-------- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/dbus/dbus-server-debug-pipe.c b/dbus/dbus-server-debug-pipe.c index 32d62dd..5da400a 100644 --- a/dbus/dbus-server-debug-pipe.c +++ b/dbus/dbus-server-debug-pipe.c @@ -166,8 +166,9 @@ _dbus_server_debug_pipe_new (const char *server_name, goto nomem_2; if (!_dbus_server_init_base (&debug_server->base, - &debug_vtable, &address)) - goto nomem_3; + &debug_vtable, &address, + error)) + goto fail_3; if (!_dbus_hash_table_insert_string (server_pipe_hash, debug_server->name, @@ -183,7 +184,7 @@ _dbus_server_debug_pipe_new (const char *server_name, nomem_4: _dbus_server_finalize_base (&debug_server->base); - nomem_3: + fail_3: dbus_free (debug_server->name); nomem_2: _dbus_string_free (&address); @@ -191,7 +192,8 @@ _dbus_server_debug_pipe_new (const char *server_name, dbus_free (debug_server); nomem_0: pipe_hash_unref (); - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + if (error != NULL && !dbus_error_is_set (error)) + _DBUS_SET_OOM (error); return NULL; } diff --git a/dbus/dbus-server-protected.h b/dbus/dbus-server-protected.h index 44f53ee..f613bf3 100644 --- a/dbus/dbus-server-protected.h +++ b/dbus/dbus-server-protected.h @@ -93,7 +93,8 @@ struct DBusServer dbus_bool_t _dbus_server_init_base (DBusServer *server, const DBusServerVTable *vtable, - const DBusString *address); + const DBusString *address, + DBusError *error); void _dbus_server_finalize_base (DBusServer *server); dbus_bool_t _dbus_server_add_watch (DBusServer *server, DBusWatch *watch); diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c index 33fba4d..8869d85 100644 --- a/dbus/dbus-server-socket.c +++ b/dbus/dbus-server-socket.c @@ -322,7 +322,8 @@ _dbus_server_new_for_socket (int *fds, } if (!_dbus_server_init_base (&socket_server->base, - &socket_vtable, address)) + &socket_vtable, address, + error)) goto failed_2; server = (DBusServer*)socket_server; diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c index 7b81079..d062eb7 100644 --- a/dbus/dbus-server.c +++ b/dbus/dbus-server.c @@ -110,7 +110,8 @@ copy_address_with_guid_appended (const DBusString *address, dbus_bool_t _dbus_server_init_base (DBusServer *server, const DBusServerVTable *vtable, - const DBusString *address) + const DBusString *address, + DBusError *error) { server->vtable = vtable; @@ -130,29 +131,32 @@ _dbus_server_init_base (DBusServer *server, server->published_address = FALSE; if (!_dbus_string_init (&server->guid_hex)) - return FALSE; + { + _DBUS_SET_OOM (error); + return FALSE; + } _dbus_generate_uuid (&server->guid); if (!_dbus_uuid_encode (&server->guid, &server->guid_hex)) - goto failed; + goto oom; server->address = copy_address_with_guid_appended (address, &server->guid_hex); if (server->address == NULL) - goto failed; + goto oom; _dbus_rmutex_new_at_location (&server->mutex); if (server->mutex == NULL) - goto failed; + goto oom; server->watches = _dbus_watch_list_new (); if (server->watches == NULL) - goto failed; + goto oom; server->timeouts = _dbus_timeout_list_new (); if (server->timeouts == NULL) - goto failed; + goto oom; _dbus_data_slot_list_init (&server->slot_list); @@ -160,7 +164,8 @@ _dbus_server_init_base (DBusServer *server, return TRUE; - failed: + oom: + _DBUS_SET_OOM (error); _dbus_rmutex_free_at_location (&server->mutex); server->mutex = NULL; if (server->watches) -- 2.1.4