From c3109c662abb15fb33fff97bab394d0c741cb1ed Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 12 May 2015 10:48:40 +0100 Subject: [PATCH 2/5] _dbus_server_new_for_socket: raise a DBusError This can currently only fail due to OOM, but I'm about to make it possible to fail for other reasons. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90414 --- dbus/dbus-server-launchd.c | 4 +--- dbus/dbus-server-socket.c | 10 +++++++--- dbus/dbus-server-socket.h | 3 ++- dbus/dbus-server-unix.c | 8 ++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/dbus/dbus-server-launchd.c b/dbus/dbus-server-launchd.c index d9d5908..818ba8c 100644 --- a/dbus/dbus-server-launchd.c +++ b/dbus/dbus-server-launchd.c @@ -185,11 +185,9 @@ _dbus_server_new_for_launchd (const char *launchd_env_var, DBusError * error) } - server = _dbus_server_new_for_socket (&launchd_fd, 1, &address, 0); + server = _dbus_server_new_for_socket (&launchd_fd, 1, &address, 0, error); if (server == NULL) { - dbus_set_error (error, DBUS_ERROR_NO_SERVER, - "Unable to listen on launchd fd %d.", launchd_fd); goto l_failed_0; } diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c index 70367c7..33fba4d 100644 --- a/dbus/dbus-server-socket.c +++ b/dbus/dbus-server-socket.c @@ -283,7 +283,8 @@ DBusServer* _dbus_server_new_for_socket (int *fds, int n_fds, const DBusString *address, - DBusNonceFile *noncefile) + DBusNonceFile *noncefile, + DBusError *error) { DBusServerSocket *socket_server; DBusServer *server; @@ -365,6 +366,10 @@ _dbus_server_new_for_socket (int *fds, failed_0: dbus_free (socket_server); + + if (error != NULL && !dbus_error_is_set (error)) + _DBUS_SET_OOM (error); + return NULL; } @@ -477,10 +482,9 @@ _dbus_server_new_for_tcp_socket (const char *host, } - server = _dbus_server_new_for_socket (listen_fds, nlisten_fds, &address, noncefile); + server = _dbus_server_new_for_socket (listen_fds, nlisten_fds, &address, noncefile, error); if (server == NULL) { - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); if (noncefile != NULL) goto failed_4; else diff --git a/dbus/dbus-server-socket.h b/dbus/dbus-server-socket.h index 44e11e8..1002960 100644 --- a/dbus/dbus-server-socket.h +++ b/dbus/dbus-server-socket.h @@ -32,7 +32,8 @@ DBUS_BEGIN_DECLS DBusServer* _dbus_server_new_for_socket (int *fds, int n_fds, const DBusString *address, - DBusNonceFile *noncefile); + DBusNonceFile *noncefile, + DBusError *error); DBusServer* _dbus_server_new_for_autolaunch (const DBusString *address, DBusError *error); DBUS_PRIVATE_EXPORT diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c index fcfe27f..f96a3d4 100644 --- a/dbus/dbus-server-unix.c +++ b/dbus/dbus-server-unix.c @@ -223,13 +223,14 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry, goto systemd_err; } - *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL); + *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL, error); if (*server_p == NULL) - goto systemd_oom; + goto systemd_err; dbus_free (fds); return DBUS_SERVER_LISTEN_OK; + systemd_oom: _DBUS_SET_OOM (error); systemd_err: @@ -335,10 +336,9 @@ _dbus_server_new_for_domain_socket (const char *path, goto failed_1; } - server = _dbus_server_new_for_socket (&listen_fd, 1, &address, 0); + server = _dbus_server_new_for_socket (&listen_fd, 1, &address, 0, error); if (server == NULL) { - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); goto failed_2; } -- 2.1.4