core: cleanup autoconnect retry handling

- clearify in the manual page that setting retry to 1 means to try
  once, without retry.
- log the initially set retry value in nm_settings_connection_get_autoconnect_retries().
- use nm_settings_connection_get_autoconnect_retries() in
  nm_settings_connection_can_autoconnect().
This commit is contained in:
Thomas Haller 2017-10-04 13:57:15 +02:00
parent f67269b49d
commit cfb14ce17e
6 changed files with 19 additions and 12 deletions

View file

@ -1647,7 +1647,7 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
*
* The number of times a connection should be tried when autoactivating before
* giving up. Zero means forever, -1 means the global default (4 times if not
* overridden).
* overridden). Setting this to 1 means to try activation once and never retry.
*/
/* ---ifcfg-rh---
* property: autoconnect-retries

View file

@ -406,8 +406,9 @@ no-auto-default=*
value applies only to connections that can auto-connect
and have a
<literal>connection.autoconnect-retries</literal> property
set to -1. If not specified, connections will be retried 4
times.
set to -1. If not specified, connections will be tried 4
times. Setting this value to 1 means to try activation once,
without retry.
</para>
</listitem>
</varlistentry>

View file

@ -691,7 +691,6 @@ handle_auth_or_fail (NMDeviceEthernet *self,
tries_left = nm_settings_connection_get_autoconnect_retries (settings_connection);
if (tries_left == 0)
return NM_ACT_STAGE_RETURN_FAILURE;
if (tries_left > 0)
nm_settings_connection_set_autoconnect_retries (settings_connection, tries_left - 1);

View file

@ -488,7 +488,6 @@ handle_auth_or_fail (NMDeviceMacsec *self,
tries_left = nm_settings_connection_get_autoconnect_retries (settings_connection);
if (tries_left == 0)
return NM_ACT_STAGE_RETURN_FAILURE;
if (tries_left > 0)
nm_settings_connection_set_autoconnect_retries (settings_connection, tries_left - 1);

View file

@ -1742,18 +1742,23 @@ device_state_changed (NMDevice *device,
if ( connection
&& old_state >= NM_DEVICE_STATE_PREPARE
&& old_state <= NM_DEVICE_STATE_ACTIVATED) {
int tries = nm_settings_connection_get_autoconnect_retries (connection);
int tries;
tries = nm_settings_connection_get_autoconnect_retries (connection);
if (nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_NO_SECRETS) {
_LOGD (LOGD_DEVICE, "connection '%s' now blocked from autoconnect due to no secrets",
nm_settings_connection_get_id (connection));
nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS);
} else if (tries != 0) {
_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left",
nm_settings_connection_get_id (connection), tries);
if (tries > 0)
nm_settings_connection_set_autoconnect_retries (connection, tries - 1);
if (tries > 0) {
_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left",
nm_settings_connection_get_id (connection), tries);
nm_settings_connection_set_autoconnect_retries (connection, --tries);
} else {
_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; infinite tries left",
nm_settings_connection_get_id (connection));
}
}
if (nm_settings_connection_get_autoconnect_retries (connection) == 0) {

View file

@ -2550,7 +2550,7 @@ nm_settings_connection_get_autoconnect_retries (NMSettingsConnection *self)
{
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
if (priv->autoconnect_retries == AUTOCONNECT_RETRIES_UNSET) {
if (G_UNLIKELY (priv->autoconnect_retries == AUTOCONNECT_RETRIES_UNSET)) {
NMSettingConnection *s_con;
int retries = -1;
const char *value;
@ -2575,6 +2575,7 @@ nm_settings_connection_get_autoconnect_retries (NMSettingsConnection *self)
if (retries == 0)
retries = AUTOCONNECT_RETRIES_FOREVER;
_LOGT ("autoconnect-retries: init %d", retries);
priv->autoconnect_retries = retries;
}
@ -2587,6 +2588,8 @@ nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *self,
{
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
nm_assert (retries == AUTOCONNECT_RETRIES_UNSET || retries >= 0);
if (priv->autoconnect_retries != retries) {
_LOGT ("autoconnect-retries: set %d", retries);
priv->autoconnect_retries = retries;
@ -2635,7 +2638,7 @@ nm_settings_connection_can_autoconnect (NMSettingsConnection *self)
const char *permission;
if ( !priv->visible
|| priv->autoconnect_retries == 0
|| nm_settings_connection_get_autoconnect_retries (self) == 0
|| priv->autoconnect_blocked_reason != NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE)
return FALSE;