From 3428a70ec49b9657651ad74f372912f7aa4d6b09 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 9 Jan 2014 10:04:30 +0900 Subject: [PATCH] [daemon-fix] Changed the way of make bus address when the address is not given When the autolaunch enabled (when using dbus-launch), the bus will be addressed by the member 'listen' of config file It has to decide the autolaunch address at run-time instead of compile-time --- bus/bus.c | 132 +++++++++++++++++++++++++++++------------------ configure.ac | 3 -- dbus/dbus-sysdeps-unix.c | 5 -- 3 files changed, 83 insertions(+), 57 deletions(-) diff --git a/bus/bus.c b/bus/bus.c index 8698db2..ee2ff9c 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -270,6 +270,47 @@ setup_server (BusContext *context, return TRUE; } +#ifdef ENABLE_KDBUS_TRANSPORT +static int +init_server_for_kdbus (BusContext *context, + const char *address, + DBusError *error) +{ + DBusBusType type; + DBusServer* server; + char* bus_address; + + if (!strcmp (context->type, "system")) + type = DBUS_BUS_SYSTEM; + else if (!strcmp (context->type, "session")) + type = DBUS_BUS_SESSION; + else + type = DBUS_BUS_STARTER; + + bus_address = make_kdbus_bus (type, address, error); + if (bus_address == NULL) + return -1; + + server = empty_server_init (bus_address); + if (server == NULL) + { + free (bus_address); + return -1; + } + if (!_dbus_list_append (&context->servers, server)) + { + free (bus_address); + return -2; + } + + context->myKdbusConnection = daemon_as_client (type, bus_address, error); + if (context->myKdbusConnection == NULL) + return -1; + + return 0; +} +#endif + /* This code only gets executed the first time the * config files are parsed. It is not executed * when config files are reloaded. @@ -434,39 +475,16 @@ process_config_first_time_only (BusContext *context, { #ifdef ENABLE_KDBUS_TRANSPORT if(!strncmp(_dbus_string_get_const_data(address), "kdbus:", strlen("kdbus:"))) - { - DBusBusType type; - DBusServer* server; - char* bus_address; - - if(!strcmp (context->type, "system")) - type = DBUS_BUS_SYSTEM; - else if(!strcmp (context->type, "session")) - type = DBUS_BUS_SESSION; - else - type = DBUS_BUS_STARTER; - - bus_address = make_kdbus_bus(type, _dbus_string_get_const_data(address), error); - if(bus_address == NULL) - goto failed; - - server = empty_server_init(bus_address); - if(server == NULL) - { - free(bus_address); - goto failed; - } - - if (!_dbus_list_append (&context->servers, server)) - { - free(bus_address); - goto oom; - } - - context->myKdbusConnection = daemon_as_client(type, bus_address, error); - if(context->myKdbusConnection == NULL) - goto failed; - } + { + int ret; + + ret = init_server_for_kdbus (context, _dbus_string_get_const_data (address), error); + + if (ret == -1) + goto failed; + else if (ret == -2) + goto oom; + } else #endif { @@ -493,27 +511,43 @@ process_config_first_time_only (BusContext *context, addresses = bus_config_parser_get_addresses (parser); link = _dbus_list_get_first_link (addresses); - while (link != NULL) +#ifdef ENABLE_KDBUS_TRANSPORT + if (!strcmp (link->data, "kdbus:")) { - DBusServer *server; + int ret; - server = dbus_server_listen (link->data, error); - if (server == NULL) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - goto failed; - } - else if (!setup_server (context, server, auth_mechanisms, error)) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - goto failed; - } + ret = init_server_for_kdbus (context, link->data, error); - if (!_dbus_list_append (&context->servers, server)) + if (ret == -1) + goto failed; + else if (ret == -2) goto oom; - - link = _dbus_list_get_next_link (addresses, link); } + else +#endif + { + while (link != NULL) + { + DBusServer *server; + + server = dbus_server_listen (link->data, error); + if (server == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + else if (!setup_server (context, server, auth_mechanisms, error)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + + if (!_dbus_list_append (&context->servers, server)) + goto oom; + + link = _dbus_list_get_next_link (addresses, link); + } + } } context->fork = bus_config_parser_get_fork (parser); diff --git a/configure.ac b/configure.ac index d92acdd..dd89f9a 100644 --- a/configure.ac +++ b/configure.ac @@ -1753,9 +1753,6 @@ elif test x$dbus_win = xyes; then # branch of the conditional because the default might conceivably # change (see #38201) DBUS_SESSION_BUS_CONNECT_ADDRESS="autolaunch:" -elif test x$enable_kdbus_transport = xyes; then - # Autolaunching kdbus bus instead of the ordinary socket - DBUS_SESSION_BUS_CONNECT_ADDRESS="autolaunch:scope=kdbus" else # The default on all other Unix platforms (notably Linux) # is to use auto-launching - this works a bit differently on Mac OS X diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 5db50e6..1cb4a58 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -3513,11 +3513,6 @@ _dbus_get_autolaunch_address (const char *scope, ++i; argv[i] = "--close-stderr"; ++i; - if(strcmp(scope, "kdbus") == 0) - { - argv[i] = "--kdbus"; - ++i; - } argv[i] = NULL; ++i; -- 2.7.4