everything: use libgudev instead of HAL; merge NM and nm-system-settings
The only thing that doesn't work yet is the system-settings service's "auto eth" connections for ethernet devices that don't have an existing connection. Might also have issues with unmanaged devices that can't provide a MAC address until they are brought up, but we'll see.
This commit is contained in:
@@ -72,9 +72,6 @@ G_DEFINE_TYPE_EXTENDED (SCPluginIfcfg, sc_plugin_ifcfg, G_TYPE_OBJECT, 0,
|
||||
|
||||
|
||||
typedef struct {
|
||||
DBusGConnection *g_connection;
|
||||
NMSystemConfigHalManager *hal_mgr;
|
||||
|
||||
GHashTable *connections;
|
||||
|
||||
gulong ih_event_id;
|
||||
@@ -86,40 +83,6 @@ typedef struct {
|
||||
} SCPluginIfcfgPrivate;
|
||||
|
||||
|
||||
static void
|
||||
check_unmanaged (gpointer key, gpointer data, gpointer user_data)
|
||||
{
|
||||
GSList **list = (GSList **) user_data;
|
||||
NMIfcfgConnection *connection = NM_IFCFG_CONNECTION (data);
|
||||
const char *udi;
|
||||
GSList *iter;
|
||||
|
||||
if (!nm_ifcfg_connection_get_unmanaged (connection))
|
||||
return;
|
||||
|
||||
udi = nm_ifcfg_connection_get_udi (connection);
|
||||
if (!udi)
|
||||
return;
|
||||
|
||||
/* Just return if the UDI is already in the list */
|
||||
for (iter = *list; iter; iter = g_slist_next (iter)) {
|
||||
if (!strcmp ((char *) iter->data, udi))
|
||||
return;
|
||||
}
|
||||
|
||||
*list = g_slist_prepend (*list, g_strdup (udi));
|
||||
}
|
||||
|
||||
static GSList *
|
||||
get_unmanaged_devices (NMSystemConfigInterface *config)
|
||||
{
|
||||
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (config);
|
||||
GSList *list = NULL;
|
||||
|
||||
g_hash_table_foreach (priv->connections, check_unmanaged, &list);
|
||||
return list;
|
||||
}
|
||||
|
||||
static void
|
||||
connection_unmanaged_changed (NMIfcfgConnection *connection,
|
||||
GParamSpec *pspec,
|
||||
@@ -152,7 +115,7 @@ read_one_connection (SCPluginIfcfg *plugin, const char *filename)
|
||||
|
||||
PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "parsing %s ... ", filename);
|
||||
|
||||
connection = nm_ifcfg_connection_new (filename, priv->g_connection, priv->hal_mgr, &error, &ignore_error);
|
||||
connection = nm_ifcfg_connection_new (filename, &error, &ignore_error);
|
||||
if (connection) {
|
||||
NMConnection *wrapped;
|
||||
NMSettingConnection *s_con;
|
||||
@@ -171,7 +134,7 @@ read_one_connection (SCPluginIfcfg *plugin, const char *filename)
|
||||
g_object_ref (connection));
|
||||
PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " read connection '%s'", cid);
|
||||
|
||||
if (nm_ifcfg_connection_get_unmanaged (connection)) {
|
||||
if (nm_ifcfg_connection_get_unmanaged_spec (connection)) {
|
||||
PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Ignoring connection '%s' and its "
|
||||
"device because NM_CONTROLLED was false.", cid);
|
||||
g_signal_emit_by_name (plugin, "unmanaged-devices-changed");
|
||||
@@ -271,11 +234,11 @@ connection_changed_handler (SCPluginIfcfg *plugin,
|
||||
gboolean *do_remove,
|
||||
gboolean *do_new)
|
||||
{
|
||||
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
|
||||
NMIfcfgConnection *tmp;
|
||||
GError *error = NULL;
|
||||
GHashTable *settings;
|
||||
gboolean new_unmanaged, old_unmanaged, ignore_error = FALSE;
|
||||
gboolean ignore_error = FALSE;
|
||||
const char *new_unmanaged = NULL, *old_unmanaged = NULL;
|
||||
|
||||
g_return_if_fail (plugin != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
@@ -285,10 +248,7 @@ connection_changed_handler (SCPluginIfcfg *plugin,
|
||||
|
||||
PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "updating %s", path);
|
||||
|
||||
tmp = (NMIfcfgConnection *) nm_ifcfg_connection_new (path, priv->g_connection,
|
||||
priv->hal_mgr,
|
||||
&error,
|
||||
&ignore_error);
|
||||
tmp = (NMIfcfgConnection *) nm_ifcfg_connection_new (path, &error, &ignore_error);
|
||||
if (!tmp) {
|
||||
/* errors reading connection; remove it */
|
||||
if (!ignore_error) {
|
||||
@@ -304,8 +264,8 @@ connection_changed_handler (SCPluginIfcfg *plugin,
|
||||
|
||||
/* Successfully read connection changes */
|
||||
|
||||
old_unmanaged = nm_ifcfg_connection_get_unmanaged (NM_IFCFG_CONNECTION (connection));
|
||||
new_unmanaged = nm_ifcfg_connection_get_unmanaged (NM_IFCFG_CONNECTION (tmp));
|
||||
old_unmanaged = nm_ifcfg_connection_get_unmanaged_spec (NM_IFCFG_CONNECTION (connection));
|
||||
new_unmanaged = nm_ifcfg_connection_get_unmanaged_spec (NM_IFCFG_CONNECTION (tmp));
|
||||
|
||||
if (new_unmanaged) {
|
||||
if (!old_unmanaged) {
|
||||
@@ -318,7 +278,7 @@ connection_changed_handler (SCPluginIfcfg *plugin,
|
||||
new_wrapped = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (tmp));
|
||||
old_wrapped = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (connection));
|
||||
|
||||
if (old_unmanaged) { /* no longer unmanaged */
|
||||
if (old_unmanaged) { /* now managed */
|
||||
NMSettingConnection *s_con;
|
||||
const char *cid;
|
||||
|
||||
@@ -364,11 +324,11 @@ handle_connection_remove_or_new (SCPluginIfcfg *plugin,
|
||||
g_return_if_fail (path != NULL);
|
||||
|
||||
if (do_remove) {
|
||||
gboolean unmanaged;
|
||||
const char *unmanaged;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
|
||||
unmanaged = nm_ifcfg_connection_get_unmanaged (connection);
|
||||
unmanaged = nm_ifcfg_connection_get_unmanaged_spec (connection);
|
||||
g_hash_table_remove (priv->connections, path);
|
||||
nm_exported_connection_signal_removed (NM_EXPORTED_CONNECTION (connection));
|
||||
|
||||
@@ -380,7 +340,7 @@ handle_connection_remove_or_new (SCPluginIfcfg *plugin,
|
||||
if (do_new) {
|
||||
connection = read_one_connection (plugin, path);
|
||||
if (connection) {
|
||||
if (!nm_ifcfg_connection_get_unmanaged (NM_IFCFG_CONNECTION (connection)))
|
||||
if (!nm_ifcfg_connection_get_unmanaged_spec (NM_IFCFG_CONNECTION (connection)))
|
||||
g_signal_emit_by_name (plugin, "connection-added", connection);
|
||||
}
|
||||
}
|
||||
@@ -454,7 +414,7 @@ hash_to_slist (gpointer key, gpointer value, gpointer user_data)
|
||||
NMIfcfgConnection *exported = NM_IFCFG_CONNECTION (value);
|
||||
GSList **list = (GSList **) user_data;
|
||||
|
||||
if (!nm_ifcfg_connection_get_unmanaged (exported))
|
||||
if (!nm_ifcfg_connection_get_unmanaged_spec (exported))
|
||||
*list = g_slist_prepend (*list, value);
|
||||
}
|
||||
|
||||
@@ -475,6 +435,43 @@ get_connections (NMSystemConfigInterface *config)
|
||||
return list;
|
||||
}
|
||||
|
||||
static void
|
||||
check_unmanaged (gpointer key, gpointer data, gpointer user_data)
|
||||
{
|
||||
GSList **list = (GSList **) user_data;
|
||||
NMIfcfgConnection *connection = NM_IFCFG_CONNECTION (data);
|
||||
const char *unmanaged_spec;
|
||||
GSList *iter;
|
||||
|
||||
unmanaged_spec = nm_ifcfg_connection_get_unmanaged_spec (connection);
|
||||
if (!unmanaged_spec)
|
||||
return;
|
||||
|
||||
/* Just return if the unmanaged spec is already in the list */
|
||||
for (iter = *list; iter; iter = g_slist_next (iter)) {
|
||||
if (!strcmp ((char *) iter->data, unmanaged_spec))
|
||||
return;
|
||||
}
|
||||
|
||||
*list = g_slist_prepend (*list, g_strdup (unmanaged_spec));
|
||||
}
|
||||
|
||||
static GSList *
|
||||
get_unmanaged_specs (NMSystemConfigInterface *config)
|
||||
{
|
||||
SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (config);
|
||||
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (config);
|
||||
GSList *list = NULL;
|
||||
|
||||
if (!priv->connections) {
|
||||
setup_ifcfg_monitoring (plugin);
|
||||
read_connections (plugin);
|
||||
}
|
||||
|
||||
g_hash_table_foreach (priv->connections, check_unmanaged, &list);
|
||||
return list;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
add_connection (NMSystemConfigInterface *config,
|
||||
NMConnection *connection,
|
||||
@@ -560,28 +557,16 @@ sc_network_changed_cb (NMInotifyHelper *ih,
|
||||
}
|
||||
|
||||
static void
|
||||
init (NMSystemConfigInterface *config, NMSystemConfigHalManager *hal_manager)
|
||||
init (NMSystemConfigInterface *config)
|
||||
{
|
||||
SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (config);
|
||||
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
|
||||
|
||||
priv->hal_mgr = g_object_ref (hal_manager);
|
||||
}
|
||||
|
||||
static void
|
||||
sc_plugin_ifcfg_init (SCPluginIfcfg *plugin)
|
||||
{
|
||||
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
|
||||
GError *error = NULL;
|
||||
NMInotifyHelper *ih;
|
||||
|
||||
priv->g_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
|
||||
if (!priv->g_connection) {
|
||||
PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " dbus-glib error: %s",
|
||||
error->message ? error->message : "(unknown)");
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
ih = nm_inotify_helper_get ();
|
||||
priv->ih_event_id = g_signal_connect (ih, "event", G_CALLBACK (sc_network_changed_cb), plugin);
|
||||
priv->sc_network_wd = nm_inotify_helper_add_watch (ih, SC_NETWORK_FILE);
|
||||
@@ -596,8 +581,6 @@ dispose (GObject *object)
|
||||
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
|
||||
NMInotifyHelper *ih;
|
||||
|
||||
g_object_unref (priv->hal_mgr);
|
||||
|
||||
ih = nm_inotify_helper_get ();
|
||||
|
||||
g_signal_handler_disconnect (ih, priv->ih_event_id);
|
||||
@@ -607,9 +590,6 @@ dispose (GObject *object)
|
||||
|
||||
g_free (priv->hostname);
|
||||
|
||||
if (priv->g_connection)
|
||||
dbus_g_connection_unref (priv->g_connection);
|
||||
|
||||
if (priv->connections)
|
||||
g_hash_table_destroy (priv->connections);
|
||||
|
||||
@@ -709,7 +689,7 @@ system_config_interface_init (NMSystemConfigInterface *system_config_interface_c
|
||||
/* interface implementation */
|
||||
system_config_interface_class->get_connections = get_connections;
|
||||
system_config_interface_class->add_connection = add_connection;
|
||||
system_config_interface_class->get_unmanaged_devices = get_unmanaged_devices;
|
||||
system_config_interface_class->get_unmanaged_specs = get_unmanaged_specs;
|
||||
system_config_interface_class->init = init;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user