From 29c71168cd17b11eed65023c97aff401d5305b01 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Mon, 31 Mar 2003 08:19:50 +0000 Subject: 2003-03-31 Havoc Pennington * dbus/dbus-transport-unix.c (_dbus_transport_new_for_domain_socket) (_dbus_transport_new_for_tcp_socket): these didn't need the "server" argument since they are always client side * dbus/dbus-server.c (dbus_server_get_address): new function * bus/main.c (main): take the configuration file as an argument. * test/data/valid-config-files/debug-allow-all.conf: new file to use with dispatch.c tests for example * bus/test-main.c (main): require test data dir * bus/bus.c (bus_context_new): change this to take a configuration file name as argument * doc/config-file.txt (Elements): add * bus/system.conf, bus/session.conf: new files * dbus/dbus-bus.c (dbus_bus_get): look for system bus on well-known socket if none set * configure.in: create system.conf and session.conf --- dbus/dbus-server-unix.c | 64 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 9 deletions(-) (limited to 'dbus/dbus-server-unix.c') diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c index 41553fe2..ee26b243 100644 --- a/dbus/dbus-server-unix.c +++ b/dbus/dbus-server-unix.c @@ -83,7 +83,7 @@ handle_new_client_fd (DBusServer *server, if (!_dbus_set_fd_nonblocking (client_fd, NULL)) return TRUE; - transport = _dbus_transport_new_for_fd (client_fd, TRUE); + transport = _dbus_transport_new_for_fd (client_fd, TRUE, NULL); if (transport == NULL) { close (client_fd); @@ -201,11 +201,13 @@ static DBusServerVTable unix_vtable = { * accept new client connections. * * @param fd the file descriptor. + * @param address the server's address * @returns the new server, or #NULL if no memory. * */ DBusServer* -_dbus_server_new_for_fd (int fd) +_dbus_server_new_for_fd (int fd, + const DBusString *address) { DBusServerUnix *unix_server; DBusWatch *watch; @@ -224,7 +226,7 @@ _dbus_server_new_for_fd (int fd) } if (!_dbus_server_init_base (&unix_server->base, - &unix_vtable)) + &unix_vtable, address)) { _dbus_watch_unref (watch); dbus_free (unix_server); @@ -259,23 +261,44 @@ _dbus_server_new_for_domain_socket (const char *path, { DBusServer *server; int listen_fd; - + DBusString address; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } + + if (!_dbus_string_append (&address, "unix:path=") || + !_dbus_string_append (&address, path)) + { + _dbus_string_free (&address); + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } listen_fd = _dbus_listen_unix_socket (path, error); _dbus_fd_set_close_on_exec (listen_fd); if (listen_fd < 0) - return NULL; + { + _dbus_string_free (&address); + return NULL; + } - server = _dbus_server_new_for_fd (listen_fd); + server = _dbus_server_new_for_fd (listen_fd, &address); if (server == NULL) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); close (listen_fd); + _dbus_string_free (&address); return NULL; } + _dbus_string_free (&address); + return server; } @@ -295,23 +318,46 @@ _dbus_server_new_for_tcp_socket (const char *host, { DBusServer *server; int listen_fd; - + DBusString address; + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!_dbus_string_init (&address, _DBUS_INT_MAX)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } + + if (!_dbus_string_append (&address, "tcp:host=") || + !_dbus_string_append (&address, host) || + !_dbus_string_append (&address, ",port=") || + !_dbus_string_append_int (&address, port)) + { + _dbus_string_free (&address); + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } listen_fd = _dbus_listen_tcp_socket (host, port, error); _dbus_fd_set_close_on_exec (listen_fd); if (listen_fd < 0) - return NULL; + { + _dbus_string_free (&address); + return NULL; + } - server = _dbus_server_new_for_fd (listen_fd); + server = _dbus_server_new_for_fd (listen_fd, &address); if (server == NULL) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); close (listen_fd); + _dbus_string_free (&address); return NULL; } + _dbus_string_free (&address); + return server; -- cgit