device: ensure unique counter for udi placeholder variable

- use a guint64 variable to avoid wrapping the counter

- cache the used ID in NMDevice. This way, the same NMDevice
  instance will get the same UDI path when it realizes
  and unrealizes multiple times.
This commit is contained in:
Thomas Haller 2020-10-09 10:27:22 +02:00
parent bba1ab0f21
commit 8cab6f151d
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -357,6 +357,8 @@ typedef struct _NMDevicePrivate {
bool assume_state_guess_assume : 1;
char *assume_state_connection_uuid;
guint64 udi_id;
GHashTable *available_connections;
char * hw_addr;
char * hw_addr_perm;
@ -5881,7 +5883,6 @@ realize_start_setup(NMDevice * self,
NMDevicePrivate * priv;
NMDeviceClass * klass;
NMPlatform * platform;
static guint32 id = 0;
NMDeviceCapabilities capabilities = 0;
NMConfig * config;
guint real_rate;
@ -5967,7 +5968,12 @@ realize_start_setup(NMDevice * self,
if (!priv->udi) {
/* Use a placeholder UDI until we get a real one */
priv->udi = g_strdup_printf("/virtual/device/placeholder/%d", id++);
if (priv->udi_id == 0) {
static guint64 udi_id_counter = 0;
priv->udi_id = ++udi_id_counter;
}
priv->udi = g_strdup_printf("/virtual/device/placeholder/%" G_GUINT64_FORMAT, priv->udi_id);
_notify(self, PROP_UDI);
}