diff options
Diffstat (limited to 'libnm-glib')
| -rw-r--r-- | libnm-glib/nm-active-connection.c | 4 | ||||
| -rw-r--r-- | libnm-glib/nm-client.c | 12 | ||||
| -rw-r--r-- | libnm-glib/nm-device.c | 5 | ||||
| -rw-r--r-- | libnm-glib/nm-object.c | 3 | ||||
| -rw-r--r-- | libnm-glib/nm-remote-connection.c | 31 | ||||
| -rw-r--r-- | libnm-glib/nm-remote-settings.c | 5 | ||||
| -rw-r--r-- | libnm-glib/nm-secret-agent.c | 23 | ||||
| -rw-r--r-- | libnm-glib/nm-vpn-plugin.c | 57 | ||||
| -rw-r--r-- | libnm-glib/tests/test-nm-client.c | 33 |
9 files changed, 61 insertions, 112 deletions
diff --git a/libnm-glib/nm-active-connection.c b/libnm-glib/nm-active-connection.c index db6e7ab7..aa79e1ac 100644 --- a/libnm-glib/nm-active-connection.c +++ b/libnm-glib/nm-active-connection.c @@ -139,8 +139,8 @@ _nm_active_connection_type_for_path (DBusGConnection *connection, else type = NM_TYPE_ACTIVE_CONNECTION; } else { - g_warning ("Error in getting active connection 'Vpn' property: (%d) %s", - error->code, error->message); + g_warning ("Error in getting active connection 'Vpn' property: %s", + error->message); g_error_free (error); type = G_TYPE_INVALID; } diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c index fc105e53..20112d69 100644 --- a/libnm-glib/nm-client.c +++ b/libnm-glib/nm-client.c @@ -513,7 +513,7 @@ activate_info_complete (ActivateInfo *info, error, info->user_data); } else if (error) - g_warning ("Device activation failed: (%d) %s", error->code, error->message); + g_warning ("Device activation failed: %s", error->message); priv->pending_activations = g_slist_remove (priv->pending_activations, info); } @@ -812,8 +812,8 @@ nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active) DBUS_TYPE_G_OBJECT_PATH, path, G_TYPE_INVALID, G_TYPE_INVALID)) { - g_warning ("Could not deactivate connection '%s': %s", - path, error ? error->message : "(unknown)"); + g_warning ("Could not deactivate connection '%s': %s", + path, NM_G_ERROR_MSG (error)); g_clear_error (&error); } } @@ -1342,7 +1342,7 @@ free_devices (NMClient *client, gboolean in_dispose) if (all_devices && all_devices->len > 0) devices = all_devices; - else if (devices && devices->len > 0) + else if (real_devices && real_devices->len > 0) devices = real_devices; if (real_devices && devices != real_devices) { @@ -1839,8 +1839,8 @@ constructed (GObject *object) GError *error = NULL; if (!nm_utils_init (&error)) { - g_warning ("Couldn't initilize nm-utils/crypto system: %d %s", - error->code, error->message); + g_warning ("Couldn't initilize nm-utils/crypto system: %s", + error->message); g_clear_error (&error); } diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c index 312f9700..3392d230 100644 --- a/libnm-glib/nm-device.c +++ b/libnm-glib/nm-device.c @@ -2198,12 +2198,11 @@ device_operation_cb (DBusGProxy *proxy, if (info->fn) info->fn (info->device, error, info->user_data); else if (error) { - g_warning ("%s: device %s %s failed: (%d) %s", + g_warning ("%s: device %s %s failed: %s", __func__, nm_object_get_path (NM_OBJECT (info->device)), info->method, - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + NM_G_ERROR_MSG (error)); } g_clear_error (&error); diff --git a/libnm-glib/nm-object.c b/libnm-glib/nm-object.c index b252dc7a..c7201cda 100644 --- a/libnm-glib/nm-object.c +++ b/libnm-glib/nm-object.c @@ -1402,11 +1402,10 @@ _nm_object_reload_property (NMObject *object, G_TYPE_INVALID, G_TYPE_VALUE, &value, G_TYPE_INVALID)) { - dbgmsg ("%s: Error getting '%s' for %s: (%d) %s\n", + dbgmsg ("%s: Error getting '%s' for %s: %s\n", __func__, prop_name, nm_object_get_path (object), - err->code, err->message); g_clear_error (&err); return; diff --git a/libnm-glib/nm-remote-connection.c b/libnm-glib/nm-remote-connection.c index 2031b27f..a4dc638a 100644 --- a/libnm-glib/nm-remote-connection.c +++ b/libnm-glib/nm-remote-connection.c @@ -31,6 +31,7 @@ #include "nm-object-private.h" #include "nm-dbus-glib-types.h" #include "nm-dbus-helpers-private.h" +#include "nm-setting-private.h" #define NM_REMOTE_CONNECTION_BUS "bus" #define NM_REMOTE_CONNECTION_DBUS_CONNECTION "dbus-connection" @@ -447,25 +448,6 @@ nm_remote_connection_get_unsaved (NMRemoteConnection *connection) /****************************************************************/ static void -replace_settings (NMRemoteConnection *self, GHashTable *new_settings) -{ - GError *error = NULL; - - if (nm_connection_replace_settings (NM_CONNECTION (self), new_settings, &error)) - g_signal_emit (self, signals[UPDATED], 0, new_settings); - else { - g_warning ("%s: error updating connection %s settings: (%d) %s", - __func__, - nm_connection_get_path (NM_CONNECTION (self)), - error ? error->code : -1, - (error && error->message) ? error->message : "(unknown)"); - g_clear_error (&error); - - g_signal_emit (self, signals[REMOVED], 0); - } -} - -static void updated_get_settings_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) @@ -489,7 +471,7 @@ updated_get_settings_cb (DBusGProxy *proxy, * object. */ hash = g_hash_table_new (g_str_hash, g_str_equal); - nm_connection_replace_settings (NM_CONNECTION (self), hash, NULL); + _nm_connection_replace_settings (NM_CONNECTION (self), hash); g_hash_table_destroy (hash); priv->visible = FALSE; @@ -498,7 +480,8 @@ updated_get_settings_cb (DBusGProxy *proxy, gs_unref_object NMConnection *self_alive = NULL; self_alive = g_object_ref (self); - replace_settings (self, new_settings); + _nm_connection_replace_settings (NM_CONNECTION (self), new_settings); + g_signal_emit (self, signals[UPDATED], 0, new_settings); g_hash_table_destroy (new_settings); /* Settings service will handle announcing the connection to clients */ @@ -629,7 +612,8 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) return FALSE; priv->visible = TRUE; self_alive = g_object_ref (initable); - replace_settings (NM_REMOTE_CONNECTION (initable), hash); + _nm_connection_replace_settings (NM_CONNECTION (initable), hash); + g_signal_emit (initable, signals[UPDATED], 0, hash); g_hash_table_destroy (hash); /* Get properties */ @@ -704,7 +688,8 @@ init_get_settings_cb (DBusGProxy *proxy, priv->visible = TRUE; self_alive = g_object_ref (init_data->connection); - replace_settings (init_data->connection, settings); + _nm_connection_replace_settings (NM_CONNECTION (init_data->connection), settings); + g_signal_emit (init_data->connection, signals[UPDATED], 0, settings); g_hash_table_destroy (settings); /* Grab properties */ diff --git a/libnm-glib/nm-remote-settings.c b/libnm-glib/nm-remote-settings.c index fa2b325f..b64743a9 100644 --- a/libnm-glib/nm-remote-settings.c +++ b/libnm-glib/nm-remote-settings.c @@ -503,7 +503,7 @@ connection_inited (GObject *source, GAsyncResult *result, gpointer user_data) if (!dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.PermissionDenied")) g_hash_table_remove (priv->pending, path); - if (print_once && error->code == DBUS_GERROR_LIMITS_EXCEEDED) { + if (print_once && g_error_matches (error, DBUS_GERROR, DBUS_GERROR_LIMITS_EXCEEDED)) { g_printerr ("Warning: libnm-glib:%s(): a D-Bus limit exceeded: %s. The application might not work properly.\n" "Consider increasing max_replies_per_connection limit in /etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf " "like <limit name=\"max_replies_per_connection\">2048</limit>", @@ -574,9 +574,8 @@ fetch_connections_done (DBusGProxy *proxy, if ( !g_error_matches (error, DBUS_GERROR, DBUS_GERROR_SERVICE_UNKNOWN) && !g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NAME_HAS_NO_OWNER) && priv->service_running) { - g_warning ("%s: error fetching connections: (%d) %s.", + g_warning ("%s: error fetching connections: %s.", __func__, - error->code, error->message ? error->message : "(unknown)"); } g_clear_error (&error); diff --git a/libnm-glib/nm-secret-agent.c b/libnm-glib/nm-secret-agent.c index a0966f9f..03290469 100644 --- a/libnm-glib/nm-secret-agent.c +++ b/libnm-glib/nm-secret-agent.c @@ -27,6 +27,7 @@ #include "nm-secret-agent.h" #include "nm-glib-enum-types.h" #include "nm-dbus-helpers-private.h" +#include "nm-setting-private.h" static void impl_secret_agent_get_secrets (NMSecretAgent *self, GHashTable *connection_hash, @@ -302,7 +303,8 @@ verify_request (NMSecretAgent *self, GError **error) { NMConnection *connection = NULL; - GError *local = NULL; + + g_return_val_if_fail (out_connection, FALSE); if (!verify_sender (self, context, error)) return FALSE; @@ -321,22 +323,11 @@ verify_request (NMSecretAgent *self, } /* Make sure the given connection is valid */ - g_assert (out_connection); - connection = nm_connection_new_from_hash (connection_hash, &local); - if (connection) { - nm_connection_set_path (connection, connection_path); - *out_connection = connection; - } else { - g_set_error (error, - NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_INVALID_CONNECTION, - "Invalid connection: (%d) %s", - local ? local->code : -1, - (local && local->message) ? local->message : "(unknown)"); - g_clear_error (&local); - } + connection = _nm_connection_new_from_hash (connection_hash); + nm_connection_set_path (connection, connection_path); + *out_connection = connection; - return !!connection; + return TRUE; } static void diff --git a/libnm-glib/nm-vpn-plugin.c b/libnm-glib/nm-vpn-plugin.c index 67ddd83b..2af9deb4 100644 --- a/libnm-glib/nm-vpn-plugin.c +++ b/libnm-glib/nm-vpn-plugin.c @@ -29,6 +29,7 @@ #include "nm-utils.h" #include "nm-connection.h" #include "nm-dbus-glib-types.h" +#include "nm-setting-private.h" static gboolean impl_vpn_plugin_connect (NMVPNPlugin *plugin, GHashTable *connection, @@ -301,12 +302,15 @@ fail_stop (gpointer data) } static void -schedule_fail_stop (NMVPNPlugin *plugin) +schedule_fail_stop (NMVPNPlugin *plugin, guint timeout_secs) { NMVPNPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); nm_clear_g_source (&priv->fail_stop_id); - priv->fail_stop_id = g_idle_add (fail_stop, plugin); + if (timeout_secs) + priv->fail_stop_id = g_timeout_add_seconds (timeout_secs, fail_stop, plugin); + else + priv->fail_stop_id = g_idle_add (fail_stop, plugin); } static void @@ -439,6 +443,7 @@ _connect_generic (NMVPNPlugin *plugin, NMConnection *connection; gboolean success = FALSE; GError *local = NULL; + guint fail_stop_timeout = 0; if (priv->state != NM_VPN_SERVICE_STATE_STOPPED && priv->state != NM_VPN_SERVICE_STATE_INIT) { @@ -448,15 +453,7 @@ _connect_generic (NMVPNPlugin *plugin, return FALSE; } - connection = nm_connection_new_from_hash (properties, &local); - if (!connection) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, - "Invalid connection: (%d) %s", - local->code, local->message); - g_clear_error (&local); - return FALSE; - } - + connection = _nm_connection_new_from_hash (properties); priv->interactive = FALSE; if (details && !vpn_class->connect_interactive) { @@ -465,22 +462,29 @@ _connect_generic (NMVPNPlugin *plugin, return FALSE; } - nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING); + nm_clear_g_source (&priv->fail_stop_id); if (details) { priv->interactive = TRUE; - success = vpn_class->connect_interactive (plugin, connection, details, error); + success = vpn_class->connect_interactive (plugin, connection, details, &local); + if (g_error_matches (local, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED)) { + /* Give NetworkManager a bit of time to fall back to Connect() */ + fail_stop_timeout = 5; + } + g_propagate_error (error, local); } else success = vpn_class->connect (plugin, connection, error); if (success) { + nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING); + /* Add a timer to make sure we do not wait indefinitely for the successful connect. */ connect_timer_start (plugin); } else { /* Stop the plugin from an idle handler so that the Connect * method return gets sent before the STOP StateChanged signal. */ - schedule_fail_stop (plugin); + schedule_fail_stop (plugin, fail_stop_timeout); } g_object_unref (connection); @@ -517,22 +521,11 @@ impl_vpn_plugin_need_secrets (NMVPNPlugin *plugin, char *sn = NULL; GError *ns_err = NULL; gboolean needed = FALSE; - GError *cnfh_err = NULL; g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE); g_return_val_if_fail (properties != NULL, FALSE); - connection = nm_connection_new_from_hash (properties, &cnfh_err); - if (!connection) { - g_set_error (err, - NM_VPN_PLUGIN_ERROR, - NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, - "The connection was invalid: '%s' / '%s' invalid: %d.", - g_type_name (nm_connection_lookup_setting_type_by_quark (cnfh_err->domain)), - cnfh_err->message, cnfh_err->code); - g_error_free (cnfh_err); - return FALSE; - } + connection = _nm_connection_new_from_hash (properties); if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets) { *setting_name = ""; @@ -572,7 +565,6 @@ impl_vpn_plugin_new_secrets (NMVPNPlugin *plugin, { NMVPNPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMConnection *connection; - GError *local = NULL; gboolean success; if (priv->state != NM_VPN_SERVICE_STATE_STARTING) { @@ -582,14 +574,7 @@ impl_vpn_plugin_new_secrets (NMVPNPlugin *plugin, return FALSE; } - connection = nm_connection_new_from_hash (properties, &local); - if (!connection) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, - "Invalid connection: (%d) %s", - local->code, local->message); - g_clear_error (&local); - return FALSE; - } + connection = _nm_connection_new_from_hash (properties); if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets) { g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED, @@ -606,7 +591,7 @@ impl_vpn_plugin_new_secrets (NMVPNPlugin *plugin, /* Stop the plugin from and idle handler so that the NewSecrets * method return gets sent before the STOP StateChanged signal. */ - schedule_fail_stop (plugin); + schedule_fail_stop (plugin, 0); } g_object_unref (connection); diff --git a/libnm-glib/tests/test-nm-client.c b/libnm-glib/tests/test-nm-client.c index da2e39e0..0da93c3f 100644 --- a/libnm-glib/tests/test-nm-client.c +++ b/libnm-glib/tests/test-nm-client.c @@ -955,12 +955,8 @@ test_connection_invalid (void) settings = nmtstc_nm_remote_settings_new (); - g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*"); - nmtst_main_loop_run (loop, 100); - g_test_assert_expected_messages (); - _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); g_assert_cmpint (connections->len, ==, 2); @@ -991,12 +987,8 @@ test_connection_invalid (void) FALSE, &path2); - g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*"); - nmtst_main_loop_run (loop, 100); - g_test_assert_expected_messages (); - _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); g_assert_cmpint (connections->len, ==, 3); @@ -1027,15 +1019,11 @@ test_connection_invalid (void) connection, FALSE); - g_test_expect_message ("libnm-glib", G_LOG_LEVEL_WARNING, "*replace_settings: error updating connection*"); - nmtst_main_loop_run (loop, 100); - g_test_assert_expected_messages (); - _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); - g_assert_cmpint (connections->len, ==, 2); + g_assert_cmpint (connections->len, ==, 3); n_found = nmtst_find_all_indexes (connections->pdata, connections->len, (gpointer *) ((const char *[]) { path0, path1, path2 }), @@ -1043,12 +1031,13 @@ test_connection_invalid (void) _test_connection_invalid_find_connections, NULL, idx); - g_assert_cmpint (n_found, ==, 2); + g_assert_cmpint (n_found, ==, 3); ASSERT_IDX (0); ASSERT_IDX (1); - g_assert_cmpint (idx[2], ==, -1); + ASSERT_IDX (2); nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + nmtst_assert_connection_unnormalizable (connections->pdata[idx[2]], 0, 0); /************************************************************************** * Modify the invalid connection again. Note that the connection stays @@ -1073,7 +1062,7 @@ test_connection_invalid (void) _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); - g_assert_cmpint (connections->len, ==, 2); + g_assert_cmpint (connections->len, ==, 3); n_found = nmtst_find_all_indexes (connections->pdata, connections->len, (gpointer *) ((const char *[]) { path0, path1, path2 }), @@ -1081,12 +1070,13 @@ test_connection_invalid (void) _test_connection_invalid_find_connections, NULL, idx); - g_assert_cmpint (n_found, ==, 2); + g_assert_cmpint (n_found, ==, 3); ASSERT_IDX (0); ASSERT_IDX (1); - g_assert_cmpint (idx[2], ==, -1); + ASSERT_IDX (2); nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); nmtst_assert_connection_unnormalizable (connections->pdata[idx[1]], 0, 0); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[2]]); /************************************************************************** @@ -1111,7 +1101,7 @@ test_connection_invalid (void) _slist_to_array (&connections, nm_remote_settings_list_connections (settings)); - g_assert_cmpint (connections->len, ==, 2); + g_assert_cmpint (connections->len, ==, 3); n_found = nmtst_find_all_indexes (connections->pdata, connections->len, (gpointer *) ((const char *[]) { path0, path1, path2 }), @@ -1119,12 +1109,13 @@ test_connection_invalid (void) _test_connection_invalid_find_connections, NULL, idx); - g_assert_cmpint (n_found, ==, 2); + g_assert_cmpint (n_found, ==, 3); ASSERT_IDX (0); ASSERT_IDX (1); - g_assert_cmpint (idx[2], ==, -1); + ASSERT_IDX (2); nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[0]]); nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[1]]); + nmtst_assert_connection_verifies_without_normalization (connections->pdata[idx[2]]); g_assert_cmpstr ("test-connection-invalid-1x", ==, nm_connection_get_id (connections->pdata[idx[1]])); #undef ASSERT_IDX |