X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bus%2Fbus.c;h=b97a047637c80b6f856b576351c95d32fcf73f26;hb=0c005b3e354d302cc92e1b82b896571d0f963dca;hp=04b1286653b9aad8cdc12226a9fd6336a3b6991d;hpb=2121ff07d5e180e5537418c8d0e69d59eafefdfc;p=platform%2Fupstream%2Fdbus.git diff --git a/bus/bus.c b/bus/bus.c index 04b1286..b97a047 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -39,6 +39,8 @@ #include #include #include +#include "kdbus-d.h" +#include #ifdef DBUS_CYGWIN #include @@ -68,6 +70,7 @@ struct BusContext unsigned int keep_umask : 1; unsigned int allow_anonymous : 1; unsigned int systemd_activation : 1; + DBusConnection *myKdbusConnection; //todo maybe can be rafctored and removed }; static dbus_int32_t server_data_slot = -1; @@ -126,6 +129,18 @@ remove_server_watch (DBusWatch *watch, _dbus_loop_remove_watch (context->loop, watch); } +static void +toggle_server_watch (DBusWatch *watch, + void *data) +{ + DBusServer *server = data; + BusContext *context; + + context = server_get_context (server); + + _dbus_loop_toggle_watch (context->loop, watch); +} + static dbus_bool_t add_server_timeout (DBusTimeout *timeout, void *data) @@ -228,7 +243,7 @@ setup_server (BusContext *context, if (!dbus_server_set_watch_functions (server, add_server_watch, remove_server_watch, - NULL, + toggle_server_watch, server, NULL)) { @@ -257,7 +272,7 @@ static dbus_bool_t process_config_first_time_only (BusContext *context, BusConfigParser *parser, const DBusString *address, - dbus_bool_t systemd_activation, + BusContextFlags flags, DBusError *error) { DBusString log_prefix; @@ -273,17 +288,24 @@ process_config_first_time_only (BusContext *context, retval = FALSE; auth_mechanisms = NULL; + pidfile = NULL; - _dbus_init_system_log (); + _dbus_init_system_log (TRUE); - context->systemd_activation = systemd_activation; + if (flags & BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION) + context->systemd_activation = TRUE; + else + context->systemd_activation = FALSE; /* Check for an existing pid file. Of course this is a race; * we'd have to use fcntl() locks on the pid file to * avoid that. But we want to check for the pid file * before overwriting any existing sockets, etc. */ - pidfile = bus_config_parser_get_pidfile (parser); + + if (flags & BUS_CONTEXT_FLAG_WRITE_PID_FILE) + pidfile = bus_config_parser_get_pidfile (parser); + if (pidfile != NULL) { DBusString u; @@ -392,6 +414,7 @@ process_config_first_time_only (BusContext *context, if (auth_mechanisms[i] == NULL) goto oom; link = _dbus_list_get_next_link (auth_mechanisms_list, link); + i += 1; } } else @@ -403,22 +426,59 @@ process_config_first_time_only (BusContext *context, if (address) { - DBusServer *server; - - server = dbus_server_listen (_dbus_string_get_const_data(address), 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; + if(!strcmp(_dbus_string_get_const_data(address), "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, 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; + } + else + { + DBusServer *server; + + server = dbus_server_listen (_dbus_string_get_const_data(address), 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; + } } else { @@ -481,7 +541,6 @@ process_config_every_time (BusContext *context, DBusString full_address; DBusList *link; DBusList **dirs; - BusActivation *new_activation; char *addr; const char *servicehelper; char *s; @@ -681,17 +740,18 @@ process_config_postinit (BusContext *context, BusContext* bus_context_new (const DBusString *config_file, - ForceForkSetting force_fork, + BusContextFlags flags, DBusPipe *print_addr_pipe, DBusPipe *print_pid_pipe, const DBusString *address, - dbus_bool_t systemd_activation, DBusError *error) { - DBusString log_prefix; BusContext *context; BusConfigParser *parser; + _dbus_assert ((flags & BUS_CONTEXT_FLAG_FORK_NEVER) == 0 || + (flags & BUS_CONTEXT_FLAG_FORK_ALWAYS) == 0); + _DBUS_ASSERT_ERROR_IS_CLEAR (error); context = NULL; @@ -710,6 +770,7 @@ bus_context_new (const DBusString *config_file, goto failed; } context->refcount = 1; + context->myKdbusConnection = NULL; _dbus_generate_uuid (&context->uuid); @@ -740,7 +801,7 @@ bus_context_new (const DBusString *config_file, goto failed; } - if (!process_config_first_time_only (context, parser, address, systemd_activation, error)) + if (!process_config_first_time_only (context, parser, address, flags, error)) { _DBUS_ASSERT_ERROR_IS_SET (error); goto failed; @@ -835,7 +896,8 @@ bus_context_new (const DBusString *config_file, if (context->pidfile) _dbus_string_init_const (&u, context->pidfile); - if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS) + if (((flags & BUS_CONTEXT_FLAG_FORK_NEVER) == 0 && context->fork) || + (flags & BUS_CONTEXT_FLAG_FORK_ALWAYS)) { _dbus_verbose ("Forking and becoming daemon\n"); @@ -907,6 +969,28 @@ bus_context_new (const DBusString *config_file, dbus_server_free_data_slot (&server_data_slot); + if(context->myKdbusConnection) + { + DBusString unique_name; + + bus_connections_setup_connection(context->connections, context->myKdbusConnection); + dbus_connection_set_route_peer_messages (context->myKdbusConnection, FALSE); + _dbus_string_init_const(&unique_name, ":1.1"); //dbus_bus_get_unique_name(context->myConnection)); this is without :1. + if(!bus_connection_complete(context->myKdbusConnection, &unique_name, error)) + { + _dbus_verbose ("Bus connection complete failed for kdbus!\n"); + _dbus_string_free(&unique_name); + goto failed; + } + _dbus_string_free(&unique_name); + + if(!register_kdbus_starters(context->myKdbusConnection)) + { + _dbus_verbose ("Registering kdbus starters for dbus activatable names failed!\n"); + goto failed; + } + } + return context; failed: @@ -958,6 +1042,16 @@ bus_context_reload_config (BusContext *context, _DBUS_ASSERT_ERROR_IS_SET (error); goto failed; } + + if(context->myKdbusConnection) + { + if(!update_kdbus_starters(context->myKdbusConnection)) + { + _dbus_verbose ("Update kdbus starters for dbus activatable names failed.\n"); + _DBUS_ASSERT_ERROR_IS_SET (error); + goto failed; + } + } ret = TRUE; bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Reloaded configuration"); @@ -1154,6 +1248,11 @@ bus_context_get_loop (BusContext *context) return context->loop; } +DBusConnection* bus_context_get_myConnection(BusContext *context) +{ + return context->myKdbusConnection; +} + dbus_bool_t bus_context_allow_unix_user (BusContext *context, unsigned long uid) @@ -1251,6 +1350,11 @@ bus_context_get_reply_timeout (BusContext *context) return context->limits.reply_timeout; } +dbus_bool_t bus_context_is_kdbus(BusContext* context) +{ + return context->myKdbusConnection != NULL; +} + void bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (3, 4); @@ -1393,9 +1497,6 @@ bus_context_check_security_policy (BusContext *context, dbus_bool_t log; int type; dbus_bool_t requested_reply; - const char *sender_name; - const char *sender_loginfo; - const char *proposed_recipient_loginfo; type = dbus_message_get_type (message); dest = dbus_message_get_destination (message); @@ -1561,9 +1662,6 @@ bus_context_check_security_policy (BusContext *context, proposed_recipient, message, &toggles, &log)) { - const char *msg = "Rejected send message, %d matched rules; " - "type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))"; - complain_about_message (context, DBUS_ERROR_ACCESS_DENIED, "Rejected send message", toggles, message, sender, proposed_recipient, requested_reply,