Commit 4672499b authored by Beniamino Galvani's avatar Beniamino Galvani

core: fix bus initialization order

We currently start the bus manager only after the creation of a
NMManager because the NMManager is needed to handle set-property bus
calls. However, objects created by NMManager
(e.g. NMDnsSystemdResolved) need a bus connection and so their
initialization currently fail.

To fix this, split nm_dbus_manager_start() in two parts: first only
create the connection and acquire the bus.  After this step the
NMManager can be set up. In the second step, set NMManager as the
set-property handler and start exporting objects on the bus.

Fixes: 297d4985
parent 0498c548
......@@ -225,7 +225,7 @@ int
main (int argc, char *argv[])
{
gboolean success = FALSE;
NMManager *manager;
NMManager *manager = NULL;
NMConfig *config;
GError *error = NULL;
gboolean wrote_pidfile = FALSE;
......@@ -395,12 +395,13 @@ main (int argc, char *argv[])
NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT,
NM_CONFIG_DEFAULT_MAIN_AUTH_POLKIT_BOOL));
manager = nm_manager_setup ();
if (!nm_dbus_manager_acquire_bus (nm_dbus_manager_get ()))
goto done_no_manager;
if (!nm_dbus_manager_start (nm_dbus_manager_get (),
nm_manager_dbus_set_property_handle,
manager))
goto done;
manager = nm_manager_setup ();
nm_dbus_manager_start (nm_dbus_manager_get(),
nm_manager_dbus_set_property_handle,
manager);
nm_dispatcher_init ();
......@@ -453,6 +454,7 @@ done:
nm_dns_manager_stop (nm_dns_manager_get ());
done_no_manager:
if (global_opt.pidfile && wrote_pidfile)
unlink (global_opt.pidfile);
......
......@@ -83,6 +83,7 @@ typedef struct {
GDBusConnection *connection;
GDBusProxy *proxy;
guint objmgr_registration_id;
gboolean started;
} NMDBusManagerPrivate;
struct _NMDBusManager {
......@@ -930,6 +931,7 @@ _obj_register (NMDBusManager *self,
nm_assert (c_list_is_empty (&obj->internal.registration_lst_head));
nm_assert (priv->connection);
nm_assert (priv->started);
n_klasses = 0;
gtype = G_OBJECT_TYPE (obj);
......@@ -1107,7 +1109,7 @@ _nm_dbus_manager_obj_export (NMDBusObject *obj)
nm_assert_not_reached ();
c_list_link_tail (&priv->objects_lst_head, &obj->internal.objects_lst);
if (priv->connection)
if (priv->connection && priv->started)
_obj_register (self, obj);
}
......@@ -1306,7 +1308,7 @@ _nm_dbus_manager_obj_emit_signal (NMDBusObject *obj,
self = obj->internal.bus_manager;
priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
if (!priv->connection) {
if (!priv->connection || !priv->started) {
nm_g_variant_unref_floating (args);
return;
}
......@@ -1453,10 +1455,28 @@ static const GDBusInterfaceInfo interface_info_objmgr = NM_DEFINE_GDBUS_INTERFAC
/*****************************************************************************/
gboolean
void
nm_dbus_manager_start (NMDBusManager *self,
NMDBusManagerSetPropertyHandler set_property_handler,
gpointer set_property_handler_data)
{
NMDBusManagerPrivate *priv;
NMDBusObject *obj;
g_return_if_fail (NM_IS_DBUS_MANAGER (self));
priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
g_return_if_fail (priv->connection);
priv->set_property_handler = set_property_handler;
priv->set_property_handler_data = set_property_handler_data;
priv->started = TRUE;
c_list_for_each_entry (obj, &priv->objects_lst_head, internal.objects_lst)
_obj_register (self, obj);
}
gboolean
nm_dbus_manager_acquire_bus (NMDBusManager *self)
{
NMDBusManagerPrivate *priv;
gs_free_error GError *error = NULL;
......@@ -1465,17 +1485,11 @@ nm_dbus_manager_start (NMDBusManager *self,
gs_unref_object GDBusProxy *proxy = NULL;
guint32 result;
guint registration_id;
NMDBusObject *obj;
g_return_val_if_fail (NM_IS_DBUS_MANAGER (self), FALSE);
priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
priv->set_property_handler = set_property_handler;
priv->set_property_handler_data = set_property_handler_data;
g_return_val_if_fail (!priv->connection, FALSE);
/* we will create the D-Bus connection and registering the name synchronously.
* The reason why that is necessary is because:
* (1) if we are unable to create a D-Bus connection, it means D-Bus is not
......@@ -1557,9 +1571,6 @@ nm_dbus_manager_start (NMDBusManager *self,
_LOGI ("acquired D-Bus service \"%s\"", NM_DBUS_SERVICE);
c_list_for_each_entry (obj, &priv->objects_lst_head, internal.objects_lst)
_obj_register (self, obj);
return TRUE;
}
......
......@@ -49,9 +49,11 @@ typedef void (*NMDBusManagerSetPropertyHandler) (NMDBusObject *obj,
GVariant *value,
gpointer user_data);
gboolean nm_dbus_manager_start (NMDBusManager *self,
NMDBusManagerSetPropertyHandler handler,
gpointer handler_data);
gboolean nm_dbus_manager_acquire_bus (NMDBusManager *self);
void nm_dbus_manager_start (NMDBusManager *self,
NMDBusManagerSetPropertyHandler set_property_handler,
gpointer set_property_handler_data);
GDBusConnection *nm_dbus_manager_get_connection (NMDBusManager *self);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment