core: fix reading device state file

For manged=unknown, we don't write the value to the
device state keyfile. The results in an empty file,
or at least, a keyfile that doesn't have device.managed
set.

On read, we must treat a missing device.managed flag as
unknown, and not as unmanaged. Otherwise, on restart
a device becomes marked as explicitly unmanaged.

This was broken by commit 142ebb1 "core: only persist explicit managed
state in device's state file", where we started conditionally
to no longer write the managed state.

Reported-by: Michael Biebl <mbiebl@debian.org>
Fixes: 142ebb1037
This commit is contained in:
Thomas Haller 2017-05-11 19:40:55 +02:00
parent 81008c90ac
commit 348ffdec18

View file

@ -1894,21 +1894,23 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf)
nm_assert (ifindex > 0);
if (kf) {
gboolean managed;
managed = nm_config_keyfile_get_boolean (kf,
DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_MANAGED,
FALSE);
managed_type = managed
? NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_MANAGED
: NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNMANAGED;
if (managed) {
switch (nm_config_keyfile_get_boolean (kf,
DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_MANAGED,
-1)) {
case TRUE:
managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_MANAGED;
connection_uuid = nm_config_keyfile_get_value (kf,
DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_CONNECTION_UUID,
NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY);
break;
case FALSE:
managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNMANAGED;
break;
case -1:
/* missing property in keyfile. */
break;
}
perm_hw_addr_fake = nm_config_keyfile_get_value (kf,