From e45e4382274149ca60c11f068ccca719f3598074 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 6 Apr 2003 18:03:03 +0000 Subject: 2003-04-06 Havoc Pennington * bus/bus.c (bus_context_new): fix wrong handling of server_data_slot_unref() in the error case. * dbus/dbus-internals.h (_dbus_assert): change so it passes "(condition) != 0" to _dbus_real_assert so that "_dbus_assert (pointer)" doesn't cause a warning * bus/main.c (main): accept --print-address option to print out the message bus address * dbus/dbus-sysdeps.c (_dbus_generate_random_ascii): export this * dbus/dbus-transport.c (_dbus_transport_open): special error for "tmpdir" option to unix: address on client side * dbus/dbus-server.c (dbus_server_listen): handle "tmpdir" option to unix: address * configure.in (TEST_SOCKET_DIR): locate a temporary directory we can use to create sockets in the test suite. * bus/main.c (signal_handler): on SIGTERM, exit the daemon cleanly. To be used for testing. * dbus/dbus-spawn.c (babysit): use _dbus_set_signal_handler() * dbus/dbus-sysdeps.c (_dbus_set_signal_handler): new * dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new): handle trying to call this when there's no servers active --- dbus/dbus-server.c | 73 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 12 deletions(-) (limited to 'dbus/dbus-server.c') diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c index 566e9178..3f877a0f 100644 --- a/dbus/dbus-server.c +++ b/dbus/dbus-server.c @@ -305,18 +305,68 @@ dbus_server_listen (const char *address, if (strcmp (method, "unix") == 0) { const char *path = dbus_address_entry_get_value (entries[i], "path"); - - if (path == NULL) + const char *tmpdir = dbus_address_entry_get_value (entries[i], "tmpdir"); + + if (path == NULL && tmpdir == NULL) { address_problem_type = "unix"; - address_problem_field = "path"; + address_problem_field = "path or tmpdir"; goto bad_address; } - server = _dbus_server_new_for_domain_socket (path, error); + if (path && tmpdir) + { + address_problem_other = "cannot specify both \"path\" and \"tmpdir\" at the same time"; + goto bad_address; + } - if (server) - break; + if (tmpdir != NULL) + { + DBusString full_path; + DBusString filename; + + if (!_dbus_string_init (&full_path)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto out; + } + + if (!_dbus_string_init (&filename)) + { + _dbus_string_free (&full_path); + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto out; + } + + if (!_dbus_string_append (&filename, + "dbus-") || + !_dbus_generate_random_ascii (&filename, 10) || + !_dbus_string_append (&full_path, tmpdir) || + !_dbus_concat_dir_and_file (&full_path, &filename)) + { + _dbus_string_free (&full_path); + _dbus_string_free (&filename); + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto out; + } + + /* FIXME - we will unconditionally unlink() the path. + * unlink() does not follow symlinks, but would like + * independent confirmation this is safe enough. See + * also _dbus_listen_unix_socket() and comments therein. + */ + + server = + _dbus_server_new_for_domain_socket (_dbus_string_get_const_data (&full_path), + error); + + _dbus_string_free (&full_path); + _dbus_string_free (&filename); + } + else + { + server = _dbus_server_new_for_domain_socket (path, error); + } } else if (strcmp (method, "tcp") == 0) { @@ -361,9 +411,6 @@ dbus_server_listen (const char *address, } server = _dbus_server_debug_new (name, error); - - if (server) - break; } else if (strcmp (method, "debug-pipe") == 0) { @@ -377,9 +424,6 @@ dbus_server_listen (const char *address, } server = _dbus_server_debug_pipe_new (name, error); - - if (server) - break; } #endif else @@ -387,7 +431,12 @@ dbus_server_listen (const char *address, address_problem_other = "Unknown address type (examples of valid types are \"unix\" and \"tcp\")"; goto bad_address; } + + if (server) + break; } + + out: dbus_address_entries_free (entries); return server; -- cgit